0

我不知道如何做到这一点,所以它会生成两个不同的数字并将其放入两个不同的文本框中我已经尝试了很多但我无法得到它

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
 <html xmlns="http://www.w3.org/1999/xhtml">
 <head>
 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
 <title>Dice Game</title>
 <style type="text/css">
 body,input{font-family:sans-serif; color:#FF0000; background-color:#990000#000000; }
 </style>
 <script type="text/javascript"language="javascript">
 function roller(){
 var num=Math.ceil(Math.random()*6);
 document.myForm.output.value=num;
 }

 </script>
 </head>

 <body>
 <form id="myForm" name="myForm"method="post"action="">
 <input type="button" name="Roll" id="Roll" value="Button" onclick="roller()"/>

 <br/>

 <input type="text" name="output" size="16" disabled="disabled" id="output"/>

 <form id="myForm" name="myForm"method="post"action="">

 <br/>

 <input type="text" name="output" size="16" disabled="disabled" id="output"/>




 </form>
 </body>
 </html>
4

1 回答 1

0

您的 HTML 比它需要的长得多。我把它清理干净并放在小提琴中:http: //jsfiddle.net/HxzcC/

HTML:

<button id="roll" onclick="roller()">Roll</button>
<br/>
<input type="text" id="input1" size="16" disabled="disabled" />
<input type="text" id="input2" size="16" disabled="disabled" />

JavaScript:

function roller(){
    var num = Math.ceil(Math.random()*6);
    document.getElementById('input1').value = num;
    var num = Math.ceil(Math.random()*6);
    document.getElementById('input2').value = num;
}
于 2013-04-11T19:20:16.230 回答