日期:2014-05-16  浏览次数:20395 次

怎样通过点击随机的按钮让它在文本框中自动产生一个随机数
随机数最好是文本加数字的,谢谢。

<form   name= "form1 "   method= "post "   action= " ">
    <table   width= "40% "     border= "0 ">
        <tr>
            <td   width= "23% "   align= "center "> a </td>
            <td   width= "77% "> <input   type= "text "   name= "u "> </td>
        </tr>
        <tr>
            <td   align= "center "> b </td>
            <td> <input   type= "text "   name= "p ">
            <input   type= "button "   name= "Submit "   value= "随机 "> </td>
        </tr>
        <tr   align= "center ">
            <td   colspan= "2 "> <input   type= "submit "   name= "Submit2 "   value= "提交 "> </td>
        </tr>
    </table>
</form>

------解决方案--------------------
<form name= "form1 " method= "post " action= " ">
<table width= "40% " border= "0 ">
<tr>
<td width= "23% " align= "center "> a </td>
<td width= "77% "> <input type= "text " name= "u "> </td>
</tr>
<tr>
<td align= "center "> b </td>
<td> <input type= "text " name= "p ">
<input type= "button " name= "Submit1 " value= "随机 " onclick= "show() "> </td>
</tr>
<tr align= "center ">
<td colspan= "2 "> <input type= "submit " name= "Submit2 " value= "提交 "> </td>
</tr>
</table>
</form>
<script language=javascript>
function show()
{
var str= "0123456789abcdefghijklmnopqrstuvwxyz "
var result= " "
for(var i=0;i <6;i++)
{
var temp=Math.floor(Math.random()*36)
result+=str.charAt(temp)
}
document.getElementById( "p ").value=result
}
</script>

------解决方案--------------------
稍微修改一下,自定义长度

<form name= "form1 " method= "post " action= " ">
<table width= "40% " border= "0 ">
<tr>
<td width= "23% " align= "center "> a </td>
<td width= "77% "> <input type= "text " name= "u "> </td>
</tr>
<tr>
<td align= "center "> b </td>
<td> <input type= "text " name= "p ">
<input type= "button " name= "