如何解决如何将 JS 代码变成 do-while ReCaptcha 循环?
我似乎无法将代码的 js 部分修改为 do-while 循环。我试过这个
做{text+=possible.charAt(Math.floor(Math.random()*5))} 而 (i
但我很确定这是不正确的。
do {text+=possible.charAt(Math.floor(Math.random()*5))}
while (i<5);
<!DOCTYPE html>
<html>
<head>
<title>Simple JavaScript Captcha Example</title>
<script type="text/javascript">
/* Function to Generat Captcha */
function GenerateCaptcha() {
var chr1 = Math.floor(Math.random() * 5)+ '';
var chr2 = Math.floor(Math.random() * 5)+ '';
var chr3 = Math.floor(Math.random() * 5)+ '';
var chr4 = Math.floor(Math.random() * 5)+ '';
var chr5 = Math.floor(Math.random() * 5)+ '';
var chr6 = Math.floor(Math.random() * 5)+ '';
var chr7 = Math.floor(Math.random() * 5)+ '';
var captchaCode = chr1 + chr2 + chr3 + chr4 + chr5+ chr6 + chr7;
document.getElementById("txtCaptcha").value = captchaCode
}
/* Validating Captcha Function */
function ValidCaptcha() {
var str1 = document.getElementById('txtCaptcha').value;
var str2 = document.getElementById('txtCompare').value;
if (str1 == str2) return true;
return false;
}
/* Remove spaces from Captcha Code */
function removeSpaces(string) {
return string.split('').join('');
}
</script>
</head>
<body onload="GenerateCaptcha();">
<h2>Generating Captcha Demo</h2>
<input type="text" id="txtCaptcha" style="text-align: center; border: none; font-weight: bold; font-family: Modern" />
<input type="button" id="btnrefresh" value="Refresh" onclick="GenerateCaptcha();" />
<input type="text" id="txtCompare" />
<input id="btnValid" type="button" value="Check" onclick="alert(ValidCaptcha());" />
</body>
</html>
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。