kar*_*m79 181
$('*[id*=mytext]:visible').each(function() {
$(this).doStuff();
});
Run Code Online (Sandbox Code Playgroud)
请注意,选择器开头的星号'*' 与所有元素匹配.
请参阅Attribute Contains Selectors,以及:visible和:hidden选择器.
dnx*_*xit 122
如果你是通过Contains找到它那么就是这样的
$("input[id*='DiscountType']").each(function (i, el) {
//It'll be an array of elements
});
Run Code Online (Sandbox Code Playgroud)
如果您通过Starts With找到它,那么它就像这样
$("input[id^='DiscountType']").each(function (i, el) {
//It'll be an array of elements
});
Run Code Online (Sandbox Code Playgroud)
如果你是通过Ends With找到它那么就像这样
$("input[id$='DiscountType']").each(function (i, el) {
//It'll be an array of elements
});
Run Code Online (Sandbox Code Playgroud)
如果要选择id不是给定字符串的元素
$("input[id!='DiscountType']").each(function (i, el) {
//It'll be an array of elements
});
Run Code Online (Sandbox Code Playgroud)
如果要选择id包含给定单词的元素,则用空格分隔
$("input[name~='DiscountType']").each(function (i, el) {
//It'll be an array of elements
});
Run Code Online (Sandbox Code Playgroud)
如果要选择id等于给定字符串或以该字符串后跟连字符开头的元素
$("input[id|='DiscountType']").each(function (i, el) {
//It'll be an array of elements
});
Run Code Online (Sandbox Code Playgroud)
por*_*ero 18
这将选择ID为'foo'并且可见的所有DIV
$("div:visible[id*='foo']");
Run Code Online (Sandbox Code Playgroud)
感谢你们俩.这对我很有用.
$("input[type='text'][id*=" + strID + "]:visible").each(function() {
this.value=strVal;
});
Run Code Online (Sandbox Code Playgroud)