找回密码
 新建账号

[JS] 用JS实现100以内的加减法验证码功能

[复制链接]
php 发表于 2012/5/15 03:58 | 显示全部楼层 |阅读模式
用 Javascript 实现 100 以内的加减运算验证码功能。

本例中使用的是加法运算,如果需要减法,则将 c!=a+b 修改为 c!=a-b 并且将 a+"+"+b+"=" 修改为 a+"-"+b+"=" 即可,当然例子中的 100 也是可以修改的.
  1. <span id="secc">Loading...</span><input id="check" size="4" /><input type="submit" value="提交"  onclick="check()" />
  2. <script language="JavaScript" type="text/javascript">
  3.         var a=Math.round(parseInt(Math.random()*100));
  4.         var b=Math.round(parseInt(Math.random()*100));        
  5.         document.getElementById('secc').innerHTML=a+"+"+b+"=";        
  6.         function check() {
  7.         var c=document.getElementById('check').value;
  8.         if (c!=a+b) {
  9.                 alert('错误');
  10.         location.href="http://www.51-n.com/";
  11.         } else {alert('正确');}
  12. }
  13. </script>
复制代码

手机版|轻松E站

GMT+8, 2024/4/20 00:32

快速回复 返回顶部 返回列表