花了一个早上,做了个JS验证码。谁知道,这东西根本没有,没法防止重复提交的。
悲剧咯!验证码本来用来防止机械的破坏,谁知道这搞的人麻烦了,还是一样被重复提交!!
求 设置 验证码思路啊……到底这个是怎么搞的啊!!
根本不知道验证码思路是怎么的,那怎么搞啊。
唉,我真浮躁,说是WEB编程,但是数据流是什么我都不知道……
- <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
- <html xmlns="http://www.w3.org/1999/xhtml" >
- <head id="Head1" runat="server">
- <title>无标题页</title>
- <!--Vali-->
- <script type="text/javascript" src="Jscript/jquery-1.3.2.min.js"></script>
- <script type="text/javascript" src="Jscript/lqyvalictrl.js"></script>
- <link rel="stylesheet" href="css/Style.css" type="text/css" />
- <!--Vali End-->
- </head>
- <body>
- <form id="form1" runat="server" >
- <div>
- <input type="text" id="txtName" value="LQY" />
- <input type="button" id="btnSubmit" value="HTMLClick" onclick="lqyCheckValidata('form1','asp');" />
- <!--<asp:Button ID="btnS" runat="server" OnClientClick="return lqyCheckValidata('form1','aspnet');" OnClick="test" Text="AspClick" />-->
- <div>测试样式有没有影响</div>
- <div style="float:left;">
- <div class="lqyCodeInput" ><input type="text" id="txtLqyValiCode" style="width:40px;padding-left:3px;" /></div>
- <div class="lqyVali" id="lqyValBox" ></div>
- </div>
- <div>测试样式有没有影响</div>
- </div>
- </form>
- </body>
- </html>
lqyvalictrl.js
- // JScript 文件
- document.write("<div class=\"lqyVali\" style=\"width:500px;display:none;\" >");
- document.write("<img src=\"ValidataCode/1_0.gif\" class=\"lqyValNumber\" alt=\"yeforVal\" />");
- document.write("<img src=\"ValidataCode/1_1.gif\" class=\"lqyValNumber\" alt=\"yeforVal\" />");
- document.write("<img src=\"ValidataCode/1_2.gif\" class=\"lqyValNumber\" alt=\"yeforVal\" />");
- document.write("<img src=\"ValidataCode/1_3.gif\" class=\"lqyValNumber\" alt=\"yeforVal\" />");
- document.write("<img src=\"ValidataCode/1_4.gif\" class=\"lqyValNumber\" alt=\"yeforVal\" />");
- document.write("<img src=\"ValidataCode/1_5.gif\" class=\"lqyValNumber\" alt=\"yeforVal\" />");
- document.write("<img src=\"ValidataCode/1_6.gif\" class=\"lqyValNumber\" alt=\"yeforVal\" />");
- document.write("<img src=\"ValidataCode/1_7.gif\" class=\"lqyValNumber\" alt=\"yeforVal\" />");
- document.write("<img src=\"ValidataCode/1_8.gif\" class=\"lqyValNumber\" alt=\"yeforVal\" />");
- document.write("<img src=\"ValidataCode/1_9.gif\" class=\"lqyValNumber\" alt=\"yeforVal\" />");
- document.write("</div>");
- var LqystrValiCode="";
- $(function ()
- {
- var lqyValNum=new Array();
- lqyValNum[0]=lqyGetRandom();
- lqyValNum[1]=lqyGetRandom();
- lqyValNum[2]=lqyGetRandom();
- lqyValNum[3]=lqyGetRandom();
- var stringbuild="";
- for (i in lqyValNum)
- {
- LqystrValiCode+= lqyValNum[i].toString();
- stringbuild+=lqyCreatePicture(lqyValNum[i].toString());
- }
- lqyShowPicture(stringbuild);
- //$('#txtLqyValiCode').val(LqystrValiCode);
- });
- function lqyShowPicture(imgitem)
- {
- document.getElementById("lqyValBox").innerHTML=imgitem;
- }
- function lqyCreatePicture(lcodeNumber)
- {
- return "<img src='"+$('.lqyValNumber').eq(lcodeNumber).attr('src')+"' alt=''/>";
- }
- function lqyCheckValidata(formid,ctrlType)
- {
- var isVali=false;
- var txt=document.getElementById("txtLqyValiCode");
- if(txt.value==LqystrValiCode)//验证编码
- {
- isVali=true;
- }
- if (isVali)
- {
- if(ctrlType=="asp")
- {
- $("#"+formid).submit();
- }
- if (ctrlType=="aspnet")
- {
- //
- }
- }
- return isVali;
- }
- function lqyGetRandom()
- {
- return parseInt(Math.random()*10);
- }
Style.css
- body {
- }
- /************************/
- .lqyVali
- {
- padding:0px 0px;
- margin:0px 0px;
- width:70px;
- height:17px;
- overflow:hidden;
- float:left;
- margin-top:3px;
- }
- .lqyVali img
- {
- padding:0px 0px;
- margin:0px 0px;
- }
- .lqyCodeInput
- {
- float:left;margin-right:5px;
- }
- /************************/
转载于:https://blog.51cto.com/snowleung/438623