Logic AND for Jquery selector

半世苍凉 提交于 2019-12-19 17:13:02

问题


I want to set to checked a checkbox input by value AND name..

<input name="email" type="checkbox" value="1" tabindex="2">

How can I do that? I need that both conditions are done.

This fails on &&

$("input[name=email] && [value='+i+']").attr('checked', true);

This code is into a for iteration and "i" is taking a numeric value. Thanks in advance for your time and help...


回答1:


Just use both selectors next to each other:

$("input[name=email][value=" + i + "]").prop('checked', true);

Any selectors that have no space between them are applied to the same element.



来源:https://stackoverflow.com/questions/14716459/logic-and-for-jquery-selector

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!