使用jQuery查找元素ID包含特定文本的页面上的所有元素
题
我正在尝试查找页面上元素ID包含特定文本的所有元素。然后,我需要根据它们是否隐藏来过滤找到的元素。非常感谢任何帮助。
其他提示
如果您通过包含找到,那么它就像这样
$("input[id*='DiscountType']").each(function (i, el) {
//It'll be an array of elements
});
如果您通过以开头找到,那么它就会像这样
$("input[id^='DiscountType']").each(function (i, el) {
//It'll be an array of elements
});
如果您通过结束找到,那么它将会是这样的
$("input[id$='DiscountType']").each(function (i, el) {
//It'll be an array of elements
});
如果要选择 id不是给定字符串
的元素 $("input[id!='DiscountType']").each(function (i, el) {
//It'll be an array of elements
});
如果您要选择 id包含给定单词的元素,请用空格分隔
$("input[id~='DiscountType']").each(function (i, el) {
//It'll be an array of elements
});
如果要选择 id等于给定字符串或以该字符串后跟连字符
开头的元素 $("input[id|='DiscountType']").each(function (i, el) {
//It'll be an array of elements
});
这将选择ID为'foo'且可见的所有DIV
$("div:visible[id*='foo']");
感谢你们两位。这对我很有用。
$("input[type='text'][id*=" + strID + "]:visible").each(function() {
this.value=strVal;
});
不隶属于 StackOverflow