简体   繁体   中英

How can I select on multiple criteria

In a web page, I have input elements, such as:

<input type="checkbox" data-initialstate="False">

The initialstate property is set when the page is built server-side.

In order to display a list of all checkboxes that were disabled, and are now disabled, I would like to make a jQuery selection, such as:

$(input and value = true and data-initialstate = false)

But I can't find the correct syntax. What is the correct way to do this?

Presumably by 'value = true' you mean checked checboxes. If so, to achieve this you can use the :checked and attribute selectors. Try this:

var $checkboxes = $('input:checkbox:checked[data-initialstate="False"]');

Note though, that this will not work if the data attribute is modified during the page lifetime. In that case you would need to use filter() , like this:

var $checkboxes = $('input:checkbox:checked').filter(function() {
  return !$(this).data('initialstate');
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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