<!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Math </title> <script type="text/javascript"> function myrandom() { document.write(Math.round(Math.random()*10)) } document.write(Math.round(Math.random()*10)) </script> </head> <body> <form> <input type="button" value="获取随机整数" onclick="myrandom()"> </form> </body> </html>
<script type="text/javascript"> function myrandom() { alert(Math.round(Math.random()*10)); } </script>
你把中间代码换成这个,可能是由于document.write 方法把按钮覆盖了吧!这种情况我也没有遇到过,奇怪 奇怪