最后的葡萄干 2017-07-13 11:31 采纳率: 100%
浏览 1124
已采纳

用JS写了一个小计算器,带时钟和一个载入的弹窗。然后为什么点击计算button结果显示一下就没了。

 <script type="text/javascript">
        function plus(){
            var num1=document.getElementById("text1").value;
            var num2=document.getElementById("text2").value;
            var result=parseInt(num1)+parseInt(num2);
            document.getElementById("text3").value=result;
        }
        function reduce(){
            var num1=document.getElementById("text1").value;
            var num2=document.getElementById("text2").value;
            var result=parseInt(num1)-parseInt(num2);
            document.getElementById("text3").value=result;
        }
        function ride(){
            var num1=document.getElementById("text1").value;
            var num2=document.getElementById("text2").value;
            var result=parseInt(num1)*parseInt(num2);
            document.getElementById("text3").value=result;
        }
        function divide(){
            var num1=document.getElementById("text1").value;
            var num2=document.getElementById("text2").value;
            var result=parseInt(num1)/parseInt(num2);
            document.getElementById("text3").value=result;
        }
        function reset(){
            document.getElementById("text1").value="";
            document.getElementById("text2").value="";
            document.getElementById("text3").value="";
        }
        function disptime()
            {
             var time = new Date( ); 
             var hour = time.getHours( );  
             var minute = time.getMinutes( );
             var second = time.getSeconds( );
                if(hour<12){    
                    if(second<10){
                        second="0"+second;
                        document.myform.myclock.value ="AM:"+hour+":"+minute+":"+second+" " ;

                            }
                    else{
                        document.myform.myclock.value ="AM:"+hour+":"+minute+":"+second+" " ;

                            }
            }
                else{
                    if(second<10){
                        second="0"+second;
                        document.myform.myclock.value ="PM:"+hour+":"+minute+":"+second+" " ;

                    }
                    else{
                        document.myform.myclock.value ="PM:"+hour+":"+minute+":"+second+" " ;

                    }
            }

             var myTime = setTimeout("disptime()",1000);
            }

        function openFirst(){
            window.open("adv.html","广告窗口","toolbars=0,location=0,statusbars=0,menubars=0,width=500,height=500,scrollbars=1,top=200,left=600");

            }
    </script>
</head>
<body onload="openFirst()">
<form name="myform">
        <table align="center">
            <tr>
                <td align="center" colspan="2" id="td1">
                    计算器
                </td>

            </tr>
            <tr>
                <td>输入第一个数字:</td>
                <td><input type="text" name="Text1" id="text1"></td>
            </tr>
            <tr>
                <td>输入第二个数字:</td>
                <td><input type="text" name="Text2" id="text2"></td>
            </tr>
            <tr>
                <td colspan="2" >

                    <span>&nbsp;</span><button onclick="plus()"><img src="图片/jia.jpg"></button><span>&nbsp;</span>
                    <span>&nbsp;</span><button onclick="reduce()"><img src="图片/jian.jpg"></button><span>&nbsp;</span>
                    <span>&nbsp;</span><button onclick="ride()"><img src="图片/cheng.jpg"></button><span>&nbsp;</span>
                    <span>&nbsp;</span><button onclick="divide()"><img src="图片/chu.jpg"></button><span>&nbsp;</span>
                </td>
            </tr>
            <tr>
                <td >结算结果:</td>
                <td><input type="text" name="Txet3" id="text3"></td>
            </tr>
            <tr>
                <td colspan="2" align="center">
                    <button value="btn" onclick="reset()"><strong>重置</strong></button>
                </td>
            </tr>
            <tr>
                <td colspan="2" align="center">
                北京时间 <INPUT name="myclock" type="text"  value="" size="10" id="text4" ><script type="text/javascript">disptime()</script>
                </td>
            </tr>
        </table>
</form>
</body>
</html>
  • 写回答

2条回答 默认 最新

  • Go 旅城通票 2017-07-14 01:07
    关注

    button按钮全部添加type="button"属性,要不默认是type="submit"提交按钮,提交表单了,

    要么把form标签去掉

            <tr>
                    <td colspan="2">
    
                        <span>&nbsp;</span><button type="button" onclick="plus()"><img src="图片/jia.jpg"></button><span>&nbsp;</span>
                        <span>&nbsp;</span><button type="button" onclick="reduce()"><img src="图片/jian.jpg"></button><span>&nbsp;</span>
                        <span>&nbsp;</span><button type="button" onclick="ride()"><img src="图片/cheng.jpg"></button><span>&nbsp;</span>
                        <span>&nbsp;</span><button type="button" onclick="divide()"><img src="图片/chu.jpg"></button><span>&nbsp;</span>
                    </td>
                </tr>
                <tr>
                    <td>结算结果:</td>
                    <td><input type="text" name="Txet3" id="text3"></td>
                </tr>
                <tr>
                    <td colspan="2" align="center">
                        <button value="btn" type="button" onclick="reset()"><strong>重置</strong></button>
                    </td>
                </tr>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 有赏,i卡绘世画不出
  • ¥15 如何用stata画出文献中常见的安慰剂检验图
  • ¥15 c语言链表结构体数据插入
  • ¥40 使用MATLAB解答线性代数问题
  • ¥15 COCOS的问题COCOS的问题
  • ¥15 FPGA-SRIO初始化失败
  • ¥15 MapReduce实现倒排索引失败
  • ¥15 ZABBIX6.0L连接数据库报错,如何解决?(操作系统-centos)
  • ¥15 找一位技术过硬的游戏pj程序员
  • ¥15 matlab生成电测深三层曲线模型代码