0
点赞
收藏
分享

微信扫一扫

js生成1-10之间的随机整数

kiliwalk 2022-07-27 阅读 75


<script>
//随机整数
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>layer-更懂你的web弹窗解决方案</title>
<script src="http://libs.baidu.com/jquery/1.9.1/jquery.min.js"></script>
<script src="layer/layer.js"></script>


</head>
<body>


<button id="test2" class="button">运行上述例子</button>


<script>
//随机整数
var n1=Math.floor(Math.random()*10+1);//输出1~10之间的随机整数
var n2=parseInt(10*Math.random());//输出0~10之间的随机整数
//弹出一个页面层
$('#test2').on('click', function(){
layer.prompt({
title: '请输入验证码:'+n1+"+"+n2+"=",
formType: 0 //prompt风格,支持0-2
}, function(pass){

var n3=n1+n2;
if(n3==pass){//判断填写的检证码是否正确
layer.prompt({title: pass+'随便写点啥,并确认', formType: 2}, function(text){
layer.msg('演示完毕!您的口令:'+ pass +' 您最后写下了:'+ text);
});
}
});
});
</script>
</body>
</html>

举报

相关推荐

0 条评论