当前位置: 代码迷 >> ASP.NET >> 小弟我的JS为什么不执行
  详细解决方案

小弟我的JS为什么不执行

热度:4453   发布时间:2013-02-25 00:00:00.0
我的JS为什么不执行啊


    <input  type="text" id="quntity" value="1"  onkeydown="autoCount()" onkeyup="autoCount()"  style="text-align:center; width:58px; height:20px;"  maxlength="3"  />
<input type="button" id="buy" value="确认无误,购买" onclick="submit()" />
        <script>
            function submit() {
                var count = parseInt(document.getElementById("quntity").value);
                if (count == "" || isNaN(count)) {
                    alert("商品数量必须为数字");
                }
            }
        </script>

------解决方案--------------------------------------------------------
经验证   执行了啊 
<html>
<body>
<input  type="text" id="quntity" value="1"  onkeydown="autoCount()" onkeyup="autoCount()"  style="text-align:center; width:58px; height:20px;"  maxlength="3"  />
<input type="button" id="buy" value="确认无误,购买" onclick="submit()" />
        <script>
            function submit() {
                alert(1)
                var count = parseInt(document.getElementById("quntity").value);alert(count);
                if (count == "" 
------解决方案--------------------------------------------------------
 isNaN(count)) {
                    alert("商品数量必须为数字");
                }
            }
        </script>
</body>
</html>

------解决方案--------------------------------------------------------
submit()函数改个名字。也许是和submit关键字冲突了。
------解决方案--------------------------------------------------------
引用:
<input  type="text" id="quntity" value="1"  onkeydown="autoCount()" onkeyup="autoCount()"  style="text-align:center; width:58px; height:20px;"  maxlength="3"  />
<input type="button" id="buy" val……

脚本段中加入alert("脚本运行了")这样便知是否运行,
不运行的猜测:
1.脚本存在语法错误,导致整个代码段未加载
2.不要使用“submit”作为函数名,换个试试!
3.脚本未指明类型!
------解决方案--------------------------------------------------------
引用:
引用:<input  type="text" id="quntity" value="1"  onkeydown="autoCount()" onkeyup="autoCount()"  style="text-align:center; width:58px; height:20px;"  maxlength="3"  />
  相关解决方案