如何在Jquery中传递多个条件来查找函数

时间:2022-10-23 20:37:59

I want to pass multiple conditions to Jquery find function e.g

我想将多个条件传递给Jquery查找函数,例如

$(selector).find("input[type='text',id='txtId']") //this is not a right way

what is the solution?

解决办法是什么?

2 个解决方案

#1


4  

The normal way to do it is like this:

正常的方法是这样的:

$("#txtId")

Why? Because you can only have one thing with that id, and therefore there is no need to use find. But maybe you could come up with a better example of what you are trying to do. It seems like I'm missing something here :)

为什么?因为你只能有一个带有id的东西,因此不需要使用find。但也许你可以想出一个更好的例子来说明你想做什么。好像我在这里遗漏了一些东西:)

#2


1  

You may find you answer here http://api.jquery.com/multiple-attribute-selector/

您可以在这里找到答案http://api.jquery.com/multiple-attribute-selector/

The docs say jQuery('[attributeFilter1][attributeFilter2][attributeFilterN]'). Anyway, if you try to select <input type="text" id="id1" class="cls1"/> by id and class, this is the way:

文档说jQuery('[attributeFilter1] [attributeFilter2] [attributeFilterN]')。无论如何,如果你试图通过id和class选择,这就是这样的:

$('input#id1.cls1')

#1


4  

The normal way to do it is like this:

正常的方法是这样的:

$("#txtId")

Why? Because you can only have one thing with that id, and therefore there is no need to use find. But maybe you could come up with a better example of what you are trying to do. It seems like I'm missing something here :)

为什么?因为你只能有一个带有id的东西,因此不需要使用find。但也许你可以想出一个更好的例子来说明你想做什么。好像我在这里遗漏了一些东西:)

#2


1  

You may find you answer here http://api.jquery.com/multiple-attribute-selector/

您可以在这里找到答案http://api.jquery.com/multiple-attribute-selector/

The docs say jQuery('[attributeFilter1][attributeFilter2][attributeFilterN]'). Anyway, if you try to select <input type="text" id="id1" class="cls1"/> by id and class, this is the way:

文档说jQuery('[attributeFilter1] [attributeFilter2] [attributeFilterN]')。无论如何,如果你试图通过id和class选择,这就是这样的:

$('input#id1.cls1')