使用 jQuery 查找页面上元素 ID 包含特定文本的所有元素

发布于 2024-07-29 07:55:11 字数 73 浏览 7 评论 0原文

我正在尝试查找页面上元素 ID 包含特定文本的所有元素。 然后,我需要根据找到的元素是否隐藏来过滤它们。 任何帮助是极大的赞赏。

I'm trying to find all elements on a page whose element ID contains a certain text. I'll then need to filter the found elements based on whether they are hidden or not. Any help is greatly appreciated.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

隔纱相望 2024-08-05 07:55:11
$('*[id*=mytext]:visible').each(function() {
    $(this).doStuff();
});

请注意选择器开头的星号“*”匹配所有元素

请参阅属性包含选择器,以及:visible:隐藏选择器。

$('*[id*=mytext]:visible').each(function() {
    $(this).doStuff();
});

Note the asterisk '*' at the beginning of the selector matches all elements.

See the Attribute Contains Selectors, as well as the :visible and :hidden selectors.

撑一把青伞 2024-08-05 07:55:11

如果您通过包含查找,那么它会像这样

    $("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
     });

如果您通过<查找 如果你想选择 name 包含给

     $("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
     });

定单词的元素,以空格分隔

     $("input[name~='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
     });

If you're finding by Contains then it'll be like this

    $("input[id*='DiscountType']").each(function (i, el) {
         //It'll be an array of elements
     });

If you're finding by Starts With then it'll be like this

    $("input[id^='DiscountType']").each(function (i, el) {
         //It'll be an array of elements
     });

If you're finding by Ends With then it'll be like this

     $("input[id$='DiscountType']").each(function (i, el) {
         //It'll be an array of elements
     });

If you want to select elements which id is not a given string

    $("input[id!='DiscountType']").each(function (i, el) {
         //It'll be an array of elements
     });

If you want to select elements which name contains a given word, delimited by spaces

     $("input[name~='DiscountType']").each(function (i, el) {
         //It'll be an array of elements
     });

If you want to select elements which id is equal to a given string or starting with that string followed by a hyphen

     $("input[id|='DiscountType']").each(function (i, el) {
         //It'll be an array of elements
     });
寒江雪… 2024-08-05 07:55:11

这将选择 ID 包含“foo”并且可见的所有 DIV

$("div:visible[id*='foo']");

This selects all DIVs with an ID containing 'foo' and that are visible

$("div:visible[id*='foo']");
小女人ら 2024-08-05 07:55:11

感谢你们俩。 这对我来说非常有效。

$("input[type='text'][id*=" + strID + "]:visible").each(function() {
    this.value=strVal;
});

Thanks to both of you. This worked perfectly for me.

$("input[type='text'][id*=" + strID + "]:visible").each(function() {
    this.value=strVal;
});
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文