- jquery each 循環(huán)元素
/**兌換前,驗(yàn)證表單信息**/
function verExcData() {
var verResult = true;
$(".receipt-info").each( function () {
if ($(this).attr("allownull") != undefined && isEmpty($(this).val())) {
$.toast("請(qǐng)輸入"+$(this).attr("namestr"), 1000)
verResult = false;
return false;
}
if ($(this).attr("minlength") != undefined && $(this).val().length < $(this).attr("minlength")) {
$.toast($(this).attr("namestr") + "長度不足" + $(this).attr("minlength") + "位", 1000)
verResult = false;
return false;
}
if ($(this).attr("maxlength") != undefined && $(this).val().length > $(this).attr("maxlength")) {
$.toast($(this).attr("namestr") + "長度超過" + $(this).attr("maxlength") + "位", 1000)
verResult = false;
return false;
}
})
return verResult;
}
jQuery中each類似于javascript的for循環(huán)
但不同于for循環(huán)的是在each里面不能使用break結(jié)束循環(huán),也不能使用continue來結(jié)束本次循環(huán),想要實(shí)現(xiàn)類似的功能就只能用return,
break 用return false
continue 用return ture