wzCommon.checkRequired = function (parent, errorStr, fn) {
var required = parent.find('.required'),
oNumber = parent.find('.number'),
oTel = parent.find('.tel'),
flag = true;
if (required.length > 0) {
required.each(function () {
var getVal = $(this).val();
if (getVal === '') {
layer.msg(errorStr, {icon: 2});
flag = false;
return false;
}
});
}
if (oNumber.length > 0) {
oNumber.each(function () {
var verifyNumber = $(this).val();
if (isNaN(verifyNumber)) {
layer.msg(errorStr, {icon: 2});
flag = false;
return false;
}
});
}
if (oTel.length > 0) {
oTel.each(function () {
var getVal = $(this).val();
debugger;
if (!wzCommon.isPhoneNo(getVal)) {
layer.msg(errorStr, {icon: 2});
flag = false;
return false;
}
});
}
if (flag) {
fn();
}
return true;
};
Ini adalah idea saya, tetapi saya tidak tahu cara menulisnya
wzCommon.checkStr = function (obj, errorStr, fn) {
if (obj.length > 0) {
obj.each(function () {
var getVal = $(this).val();
if (这里是不同条件) {
layer.msg(errorStr, {icon: 2});
flag = false;
return false;
}
});
}
if (flag) {
fn();
}
return true;
};
diperlukan = ibu bapa.cari('.diperlukan'),