HTML 两个人投骰子,比输赢

<!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>无标题文档</title>
</head>
<script src="jquery-2.1.0.js"></script>
<body>
张三的骰子 <input type="text" id="a"/><br /><br />
李四的骰子 <input type="text" id="b"/><br />
<p style="margin-left:30px">获胜者 <input type="text" id="c"/></p>
<input type="button" value="随机" onclick="butt()"/>
<input type="button" value="不玩了" onclick="bwl()" style="margin-left:140px"/>
<script>
    function butt(){
        var a = document.getElementById('a').value=(Math.random()*(6-1)+1).toFixed(0);
        var b = document.getElementById('b').value=(Math.random()*(6-1)+1).toFixed(0);
        if(a>b){
            $(function(){
                $("#c").val("张三");
                });
            }else if(a<b){
                $("#c").val("李四");
            }else{
                $("#c").val("平局");
            }
    }
    
     function bwl(){
         $("#a,#b,#c").val("");
    }
    
</script>
 <!--   /**
     * 1
 
     document.write(Math.random());
     返回随机数
     1
 
     document.write(Math.random()*(20-10)+10);
     返回10-20的随机数
     1
     document.write(Math.random()*(n-m)+m);
     返回指定范围的随机数(m-n之间)的公式[1]
     http://www.jb51.net/article/45884.htm
     */
      
     -->
</body>
</html>

posted @ 2017-10-15 20:18  4027  阅读(160)  评论(0)    收藏  举报