兄弟们 这是我在网上找的源码,因为不懂js,所以只能试,应该是调用mathrand函数 生成六位随机数字,然后赋值给一个文本框,可是 现在点了提交,没反应,我想实现的就是 能让我看到这个数字,显示出来就可以了,我用的是asp 想通过这个函数 生成一个随机数字 然后赋值给我的变量就可以了,兄弟们帮忙啊
</head>
<script type="text/javascript">
function MathRand()
{
var Num="";
for(var i=0;i<6;i++)
{
Num+=Math.floor(Math.random()*10);
}
document.getElementById("newpass").innerText=Num;
document.getElementById("newpass").innerHTML=Num; }
</script><body>
<form id="form1" name="form1" method="post" action="">
<input type="text" name="newpass" id="newpass" />
<input type="submit" name="button" id="button" value="提交" onclick="MathRand()" />
</form>
</body>
</html>
</head>
<script type="text/javascript">
function MathRand()
{
var Num="";
for(var i=0;i<6;i++)
{
Num+=Math.floor(Math.random()*10);
}
document.getElementById("newpass").innerText=Num;
document.getElementById("newpass").innerHTML=Num; }
</script><body>
<form id="form1" name="form1" method="post" action="">
<input type="text" name="newpass" id="newpass" />
<input type="submit" name="button" id="button" value="提交" onclick="MathRand()" />
</form>
</body>
</html>
document.getElementById("newpass").innerText=Num;
document.getElementById("newpass").innerHTML=Num; 换成document.getElementById("newpass").value=Num;
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<script type="text/javascript" src="jquery/jb51.net/jquery1.71/jquery-1.7.1.js"></script>
<script type="text/javascript">
function MathRand(){
var Num="";
for(var i=0;i<6;i++) {
Num+=Math.floor(Math.random()*10);
}
document.getElementById("newpass").value=Num;
return false;// return true
}
</script>
</head><body>
<form id="form1" name="form1" method="post" action="">
<input type="text" name="newpass" id="newpass" />
<input type="submit" name="button" id="button" value="提交" onclick="return MathRand()" />
</form>
</body>
</html>
应为你提交后数据消失的
稍取巧点:Math.round(900000*Math.random()+100000);即可至于赋值给文本框:document.getElementById("newpass").value=值;你的按钮是submit,又是在表单里,所以你看不到效果。把submit改成button看效果吧