简体   繁体   中英

Need to select a drop down list element with a particular attribute value from a list of drop down lists and set its selected value

.FilterList is the class name of all the drop down lists

var $lists = $('.FilterList[ctype="' + ctype + '"]').css('display', 'inline');

Something like the below works fine but I was wondering if there's a more concise and efficient method I could use instead of the .each()

 $lists.each(function () { $(this).attr('filterid') == filterid ? $(this).val(thisval) : null; });

Whilst I am after something more like:

$lists.first('.FilterList[filterid = "' + filterid + '"]').val(thisval);

Your question is a little vague without any HTML to demonstrate what you're trying to grab from the DOM, but from what I gather, it seems like something like this should work:

$lists.find("[filterid='" + filterId + "']").val(myVal);

Honestly, though, I'm just guessing at what it is you are looking for. Try creating a jsFiddle to give us a better idea of what you're after.

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