我有以下格式的字段:
<input type="text" name="cities[]" id="city_zip1"/>
<input type="text" name="cities[]" id="city_zip2"/>
<input type="text" name="cities[]" id="city_zip3"/>
有没有办法使验证插件需要第一个,但保留名称不变? 或者将这三项之一设为必需,但保留名称不变。
最佳答案
例如,点击即可完成。可以在提交时完成。
$("#checkforvalue").click(function(e) {
e.preventDefault();
if ($("input#place_of_services:checked").val()) {
var zipentered = false;
$("input[id^='city_zip']").each(function() {
if ($(this).val().length) {
zipentered = true;
}
});
if (zipentered) {
alert("value in one of the fields");
} else {
alert("no value entered");
}
}
});
关于jquery 验证输入但使用 id 来识别字段,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7159907/