日期:2014-05-16 浏览次数:20399 次
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <title>test</title> <script type="text/javascript" src="js/jquery-1.4.4.min.js"></script> <script type="text/javascript"> $(document).ready(function(){ var input = $("body").find("input[name=question]"); if(input.length==0) { alert("找不到question"); //这里可以改成return false } else { input.each(function(i){ if($(this).val() == "") { alert("第" + i + "个quesiton是空的"); //这里可以改成return false } }); } }); </script> </head> <body> <div> <input type="text" name="question" /> <input type="text" name="question" /> <input type="text" name="question" /> </div> </body> </html>
------解决方案--------------------
function test(){ var list = $("input[name='question']"); var result = list.length > 0; list.each(function(){ if($(this).val() == "") { result = false; return false; } }); return result; }
------解决方案--------------------
<script src="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.4.2.min.js"></script> <input type="text" name="question" /> <input type="text" name="question" /> <input type="text" name="question" /> <input type="button" value="检查" onclick="alert(ck())"/> <script> function ck(){ var ipq = $(":input[name='question']"); var ipqv = $(":input[name='question'][value='']"); if(ipq.length==0 || ipqv.length>0){ return false; }else{ return true; } } </script>