jQuery 按类和属性获取

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7655909/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-27 00:08:09  来源:igfitidea点击:

jQuery get by class and attribute

jquery

提问by AnonyMouse

Hi I have a select like:

嗨,我有一个选择:

<select id="item_OfficeUserId" class="dropdownauditor" name="item.OfficeUserId" invoicelineid="33">

In jQuery I can get it by its class:

在 jQuery 中,我可以通过它的类来获取它:

$(".dropdownauditor")

Is there a way to get it based on its class and it attribute invoicelineid="33" as well?

有没有办法根据它的类来获取它,并且它也属性invoicelineid =“33”?

There will be more than one with class="dropdownauditor". I want to get the selected item of the particular select. I was using:

将不止一个与class="dropdownauditor". 我想获取特定select. 我正在使用:

$(".dropdownauditor").change(function () {
    $(".dropdownauditor option:selected").each(function () {
    ...
    }
}

But this is running through the second part twice. ie. It tis then finding the selected for every selectwith class="dropdownauditor"Is is possible to only find only one with invoicelineid="33"?

但这两次贯穿第二部分。IE。然后,它正寻求在选择每一个selectclass="dropdownauditor"是可能仅发现只有一个invoicelineid="33"

回答by Andrew Whitaker

$(".dropdownauditor[invoicelineid='33']")

Using the attribute equals selector.

使用属性 equals selector