简体   繁体   English

如何通过jquery通配符搜索数据属性的精确包含值?

[英]How to search exact contain value by jquery wild card for data attribute?

I am using data_attribute in the page and i have followings element with data attribute.我在页面中使用了 data_attribute,并且我有以下带有 data 属性的元素。

No. 1.<div class="row hidden" data-party-registration-source-type-id="1">
    2.<div class="row hidden" data-party-registration-source-type-id="2,3">
    3.<div class="row hidden" data-party-registration-source-type-id="3">
    4.<div class="row hidden" data-party-registration-source-type-id="4,5">
    5.<div class="row hidden" data-party-registration-source-type-id="11">
    6.<div class="row hidden" data-party-registration-source-type-id="10">

Now i want to show all div that have data-party-registration-source-type-id =3 It will show No.2 and 3. I am using this to search现在我想显示所有具有 data-party-registration-source-type-id =3 的 div 它会显示 No.2 和 3。我用这个来搜索

var partyRegistrationSourceId = $partyRegistrationSourceTypes.val();

 $('[data-party-registration-source-type-id*=' + partyRegistrationSourceId + ']').removeClass("hidden");

It is working fine, now the problem is, when i want to search with id "1", it brings number 1,5,6.它工作正常,现在的问题是,当我想用​​ id "1" 搜索时,它会带来数字 1,5,6。 Every id that contains 1, it bring it.每个包含 1 的 id,它都会带来它。 I only want with the id 1. How i can do this?我只想要 id 1。我怎么能做到这一点? if i use this:如果我使用这个:

$('[data-party-registration-source-type-id=' + partyRegistrationSourceId + ']').removeClass("hidden");

Then it will work in this case but not working in above case.然后它将在这种情况下工作,但在上述情况下不起作用。 How i can search all id that contains exact id?我如何搜索包含确切 ID 的所有 ID?

you could try adding kind of separators for each key:您可以尝试为每个键添加一种分隔符:

<div class="row hidden" data-party-registration-source-type-id="{1}">
<div class="row hidden" data-party-registration-source-type-id="{2},{3}">
<div class="row hidden" data-party-registration-source-type-id="{3}">

var partyRegistrationSourceId = $partyRegistrationSourceTypes.val();

$("[data-party-registration-source-type-id*='{" + partyRegistrationSourceId + "}']").removeClass("hidden");

Let me know if suits your problem or is not what you need让我知道是否适合您的问题或不是您需要的

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM