日期:2014-05-16 浏览次数:20408 次
function pd() { var a = document.getElementById("l").value; //先确保这个id在你的页面存在啊 for (i = 0; i < a; i++) { if (document.getElementById("d" + i).value == "") { alert("数量不能为空") //break return; //要return 才阻止程序继续往下走 } } //this.form1.submit() document.form1.action = "PI.ASP"; //直接设定form的action 提交到asp页面 document.form1.submit(); //提交form //window.location.href = "PI.ASP" }
------解决方案--------------------
<html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title></title> </head> <body style="width:120px;"> <form action="PI.ASP" method="post" name="form1"> <table> <tr> <td><input type="text" id="l1"></td> <td><input type="text" id="l2"></td> </tr> </table> <input type="button" onclick="pd()" value="click me"> </form> <script type="text/javascript"> function pd(){ var inps = document.getElementsByTagName('input'), len = inps.length,is_true = true; for(var i = 0; i < len; i++){ if(inps[i].value == '' && inps[i].type == 'text'){ is_true = false; } } if(is_true){ document.form1.submit(); }else{ alert('文本框不能为空') } }; </script> </body> </html>