javascript - 验证动态添加的必填字段时出现问题
问题描述
我有一个检查必填字段的通用脚本。应始终填写具有“必填”属性的字段。问题是现在我有一个强制输入,这取决于从其他输入中选择的选项,所以我动态添加/删除属性,但脚本没有检测到它。
有任何想法吗?我把功能代码留在这里
希望你理解 :D
function checkMandatory(id){
var valid = true;
var selector = "input[mandatory='']";
if(id){
selector = "#"+id+" :input[mandatory='']";
}
$(selector).each(function(){
if($(this).val().trim()=="") {
invalidarInput($(this), "The field is mandatory.");
valid = false;
}
else {
$(this).val($(this).val().trim());
$(this).removeClass("invalido");
$(this).removeClass("tooltip");
$(this).removeAttr("ttip");
$(this).removeAttr("title");
$(this).unbind("mouseover");
$(this).unbind("mouseout");
}
});
return valid;
}
解决方案
推荐阅读
- python-2.7 - 如何将字符串附加到python中文本文件的特定行?
- vba - 从另一个工作表复制数据,每个条目之间有 4 行
- python - StringIO() 参数 1 必须是字符串或缓冲区,而不是 cStringIO.StringIO
- c# - 根据复选框值更新 datagridview - 循环所有行的复选框并检查是否已选中任何复选框
- sqlite - ionic 3中Sqlite查询的错误输出
- c# - 托管 ODP.Net - SELECT 中的参数导致只读列
- python - 如何用folium在地图上画弧线
- vb.net - 读取数据并将值存储在数组中
- javascript - 使用 d3pie.js 饼图更新数据时出错
- java - Java 批处理:如何以编程方式确定您正在运行哪个分区?