我在页面上使用JS动态生成输入标签。 它们使用$("#input1").val(value)
初始化。我怎样才能找到基于文本的特定输入元素?通过文本查找元素
$("input[name='DeviceIP']").each(function(index,elem){$(elem).val(value)});
我现在使用的解决方案是选择所有我想要检查,然后使用查找输入:
的值如下被初始化。
$("[name='DeviceIP']").filter(function(index, elem) {
var res = false;
var _this = this;
$("[name='DeviceIP']").each(function(index2, elem2) {
if(elem2 !== _this) {
if(_this.value === elem2.value) {
errMessage = "error text";
res = true;
}
}
});
return res;
}
我看了看这个问题here,但“:包含”(?也许是因为没有值的属性)并没有出于某种原因找到他们
:含有着眼于元素中的文本不能在价值属性。目前的方法有什么问题吗? –
您在'input1'之前缺少'.'或'#'。 –
@MihaiVilcu它只是不起作用http://jsbin.com/ketejax/edit?html,js,console,output –