<script type="text/javascript">
var errorExist = false;
$(document).ready(function(){
$("#form3").submit(function(){
var get_count = $("#form3 input[type=text]").length;
for(i=1; i<=get_count; i++){
if($(".qtyy"+i).val()==""){
errorExist = "true";
}
}
if(errorExist == "true"){
errorExist = false;
alert("Please enter value");
return false;
}
});
});
</script>
<form action="" name="form3" id="form3" method="post">
<input name="qtyy[]" type="text" class="qtyy1" size="7" />
<input name="qtyy[]" type="text" class="qtyy2" size="7" />
<input name="qtyy[]" type="text" class="qtyy3" size="7" />
<input name="qtyy[]" type="text" class="qtyy4" size="7" />
<input name="qtyy[]" type="text" class="qtyy5" size="7" />
<input type="submit" value="Place Your Order" name="postorder" id="postorder" />
</form>
问问题
1311 次
3 回答
1
试试这个,
<html>
<head>
<script src="http://code.jquery.com/jquery-latest.js"></script>
<script type="text/javascript">
var errorExist = false;
$(document).ready(function(){
$("#form3").submit(function(){
var get_count = $("#form3 input[type=text]").length;
for(i=1; i<=get_count; i++){
if($(".qtyy"+i).val()==""){
errorExist = "true";
}
}
if(errorExist == "true"){
errorExist = false;
alert("Please enter value");
return false;
}
});
});
</script>
</head>
<body>
<form action="" name="form3" id="form3" method="post">
<input name="qtyy[]" type="text" class="qtyy1" size="7" />
<input name="qtyy[]" type="text" class="qtyy2" size="7" />
<input name="qtyy[]" type="text" class="qtyy3" size="7" />
<input name="qtyy[]" type="text" class="qtyy4" size="7" />
<input name="qtyy[]" type="text" class="qtyy5" size="7" />
<input type="submit" value="Place Your Order" name="postorder" id="postorder" />
</form>
</body>
</html>
于 2013-03-02T06:57:49.540 回答
1
我觉得这是您要实现的逻辑。如果任何文本框值不为空,则表单应验证
<html>
<head>
<script src="http://code.jquery.com/jquery-latest.js"></script>
<script type="text/javascript">
var errorExist = false;
$(document).ready(function(){
$("#form3").submit(function(){
var get_count = $("#form3 input[type=text]").length;
errorExist = "true";
for(i=1; i<=get_count; i++){
if($(".qtyy"+i).val()!=""){
errorExist = "false";
}
}
if(errorExist == "true"){
errorExist = false;
alert("Please enter value");
return false;
}
});
});
</script>
</head>
<body>
<form action="" name="form3" id="form3" method="post">
<input name="qtyy[]" type="text" class="qtyy1" size="7" />
<input name="qtyy[]" type="text" class="qtyy2" size="7" />
<input name="qtyy[]" type="text" class="qtyy3" size="7" />
<input name="qtyy[]" type="text" class="qtyy4" size="7" />
<input name="qtyy[]" type="text" class="qtyy5" size="7" />
<input type="submit" value="Place Your Order" name="postorder" id="postorder" />
</form>
</body>
</html>
于 2013-03-02T07:44:11.797 回答
0
$(document).ready(function(){
$("#form3").submit(function(){
$("> input[type=text]",this).each(function(){
if($(this).val()==""){
alert("Please enter value");
return false;
}
})
})
});
于 2013-03-02T07:02:45.827 回答