我有三个选择器,目前如果其中任何一个没有被选中,警告消息是“请填写字段”。
但是,我想要自定义警报。
假设3个选择器中只有1个没有被选中,那么我该如何将警报修改为“请填写字段-2”?
我当前的代码是:
if (
checkforNullEmptySelect("group")
&& checkforNullEmptySelect("one")
&& checkforNullEmptySelect("two")
&& checkforNullEmptySelect("three")
) {
// alert("Values filled in correctly");
formValid = true
getData();
return true;
} else {
alert(alertMessageArr.correctFields);
return false;
}发布于 2019-02-26 19:20:06
如果使用的是es6,则可以使用"+“运算符或连接选择器。
// ES5 ->警告(‘请填写字段-’+选择器);
//ES6 ->告警(Please fill out the fields - ${selector});
发布于 2019-02-26 19:25:36
我假设您的HTML结构如下所示:
<input id="one" type="text"/>
<input id="two" type="text"/>
<input id="three" type="text"/>要检查字段是否为空的代码段:
if(inputOne === 0 && inputTwo === 0 && inputThree === 0){
alert("Please fill all fields");
}else{
$('input').each(function() {
if ($(this).val() != '') { //Or $(this).length > 0
alert('all inputs filled');
}
else{
alert('theres an empty input'); //alert selectors if needed
return false
}
});
}https://stackoverflow.com/questions/54884212
复制相似问题