:输入选择器返回按钮但是:not([type = button])不起作用

时间:2023-01-28 09:28:58

I'm combining selectors in order to select only specific inputs in my html :

我正在组合选择器,以便只选择我的html中的特定输入:

$('.content_container :input[type=radio]:checked, .content_container :input:not([type=radio])')

The problem there is that it also returns the <button type='button'>

问题是它还返回

I have tried adding the following:

我尝试添加以下内容:

.content_container :input:not([type=button])
.content_container :button:not([type=button])

To my selector, but it still returns the button. How can I arrange this ?

到我的选择器,但它仍然返回按钮。我怎么安排这个?

1 个解决方案

#1


2  

You need to combine both types in a single :not().

您需要将两种类型组合在一起:not()。

.content_container :input:not([type=radio],[type=button])

Otherwise, the selector with :not([type=radio]) returns all the other types of inputs, including buttons, and the selector with :not([type=button]) returns all the other inputs, including radios, so when you combine them you get both radios and buttons, instead of excluding both.

否则,选择器:not([type = radio])返回所有其他类型的输入,包括按钮,选择器:not([type = button])返回所有其他输入,包括无线电,所以当你将它们组合起来就可以获得无线电和按钮,而不是将两者都排除在外

#1


2  

You need to combine both types in a single :not().

您需要将两种类型组合在一起:not()。

.content_container :input:not([type=radio],[type=button])

Otherwise, the selector with :not([type=radio]) returns all the other types of inputs, including buttons, and the selector with :not([type=button]) returns all the other inputs, including radios, so when you combine them you get both radios and buttons, instead of excluding both.

否则,选择器:not([type = radio])返回所有其他类型的输入,包括按钮,选择器:not([type = button])返回所有其他输入,包括无线电,所以当你将它们组合起来就可以获得无线电和按钮,而不是将两者都排除在外