很奇怪的 点第一个按扭 出现的验证码验证不会成功 反倒是确定 (确认错误刷新验证码) 出现的验证码就可以
另外 怎么按扭上也会出现验证码 本来就只是想让在弹出窗口出现的
var code ; //在全局 定义验证码
function createCode()
{
code = "";
var codeLength = 6;//验证码的长度
var checkCode = document.getElementById("checkCode");
var selectChar = new Array(0,1,2,3,4,5,6,7,8,9,'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z');//所有候选组成验证码的字符,当然也可以用中文的
for(var i=0;i<codeLength;i++)
{
var charIndex = Math.floor(Math.random()*36);
code +=selectChar[charIndex];
}
//alert(code);
if(checkCode)
{
checkCode.className="code";
checkCode.value = code;
}
alert(code);
}
function validate ()
{
var inputCode = document.getElementById("input1").value;
if(inputCode.length <=0)
{
alert("请输入验证码!");
}
else if(inputCode != code )
{
alert("验证码输入错误!");
createCode();//刷新验证码
}
else
{
alert("^-^ OK");
}
}
<form action="">
<input type="text" id="input1" />
<input type="submit" onclick="createCode()" id="checkCode" style="width: 80px" value="获取验证码" /></form></br />
<input id="Button1" onclick="validate();" type="submit" value="确定" />
</form>
另外 怎么按扭上也会出现验证码 本来就只是想让在弹出窗口出现的
var code ; //在全局 定义验证码
function createCode()
{
code = "";
var codeLength = 6;//验证码的长度
var checkCode = document.getElementById("checkCode");
var selectChar = new Array(0,1,2,3,4,5,6,7,8,9,'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z');//所有候选组成验证码的字符,当然也可以用中文的
for(var i=0;i<codeLength;i++)
{
var charIndex = Math.floor(Math.random()*36);
code +=selectChar[charIndex];
}
//alert(code);
if(checkCode)
{
checkCode.className="code";
checkCode.value = code;
}
alert(code);
}
function validate ()
{
var inputCode = document.getElementById("input1").value;
if(inputCode.length <=0)
{
alert("请输入验证码!");
}
else if(inputCode != code )
{
alert("验证码输入错误!");
createCode();//刷新验证码
}
else
{
alert("^-^ OK");
}
}
<form action="">
<input type="text" id="input1" />
<input type="submit" onclick="createCode()" id="checkCode" style="width: 80px" value="获取验证码" /></form></br />
<input id="Button1" onclick="validate();" type="submit" value="确定" />
</form>
function createCode()
{
code = "";
var codeLength = 6;//验证码的长度
var checkCode = document.getElementById("checkCode");
var selectChar = new Array(0,1,2,3,4,5,6,7,8,9,'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z');//所有候选组成验证码的字符,当然也可以用中文的
for(var i=0;i<codeLength;i++)
{
var charIndex = Math.floor(Math.random()*36);
code +=selectChar[charIndex];
}
//alert(code);
if(checkCode)
{
checkCode.className="code";
checkCode.value = code;
}
document.getElementById("cc").innerHTML=code;
alert(code);
}
function validate ()
{
var inputCode = document.getElementById("input1").value;
if(inputCode.length <=0)
{
alert("请输入验证码!");
}
else if(inputCode != code )
{
alert("验证码输入错误!");
createCode();//刷新验证码
}
else
{
alert("^-^ OK");
}
} <body>
<form action="">
<input type="text" id="input1" /> <input type="button" onclick="createCode()" id="checkCode" style="width: 80px" value="获取验证码" />
<br />
<div id="cc">默认值</div>
<input id="submit" onclick="validate();" type="submit" value="确定" />
</form>
</body>
var code ; //在全局 定义验证码
function createCode()
{
code = "";
var codeLength = 6;//验证码的长度
var checkCode = document.getElementById("checkCode");
var selectChar = new Array(0,1,2,3,4,5,6,7,8,9,'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z');//所有候选组成验证码的字符,当然也可以用中文的
for(var i=0;i<codeLength;i++)
{
var charIndex = Math.floor(Math.random()*36);
code +=selectChar[charIndex];
}
//alert(code);
if(checkCode)
{
checkCode.className="code";
checkCode.value = code;
}
return false;
}
function validate ()
{
var inputCode = document.getElementById("input1").value;
if(inputCode.length <=0)
{
alert("请输入验证码!");
return false;
}
else if(inputCode != code )
{
alert("验证码输入错误!");
createCode();//刷新验证码
}
else
{
alert("^-^ OK");
}
}
</script>
<form action="">
<input type="text" id="input1" />
<input type="submit" onclick="return createCode()" id="checkCode" style="width: 80px" value="获取验证码" /></br />
<input id="Button1" onclick="return validate();" type="submit" value="确定" />
</form>
按钮出现验证吗是你加了这段代码 checkCode.value = code;
楼主应该先用develop bar调试一下