[英]not jQuery selector
This Meteor client code tries to apply the jQuery .serializeArray
on the form
but not the elements which have the class inactive
这颗流星的客户端代码尝试应用了jQuery
.serializeArray
上的form
但不具有类的元素inactive
const inputData = $('form:not[class="inactive"]').serializeArray();
Why is it failing and how to fix it? 为什么会失败以及如何解决? Thanks
谢谢
Fundamentally, to leave elements out of serializeArray
, you need to make them disabled or remove their name
. 从根本上讲,要将元素保留在
serializeArray
,则需要将其禁用或删除其name
。 So for instance: 因此,例如:
const inputData = $('form')
.find('.inactive')
.prop("disabled", true)
.end()
.serializeArray();
That: 那:
disabled
disabled
.end()
) .end()
) Re the :not
selector you tried to use, there were a few problems: 关于您尝试使用的
:not
选择器,有一些问题:
You've used []
instead of ()
around the :not
condition 您在
:not
条件周围使用了[]
而不是()
You should use a class selector, not an attribute selector, when using classes 使用类时,应使用类选择器,而不是属性选择器
You were applying it to the form
, not to elements within the form 你它是适用于该
form
,而不是表单中的元素
But since you need to call serializeArray
on the form , we need a different approach altogether (as above). 但是由于您需要在表单上调用
serializeArray
,因此我们需要完全不同的方法(如上所述)。
When using a :not
selector, keep the following things in mind: 使用
:not
选择器时,请记住以下几点:
()
for :not
instead of []
()
用作:not
而不是[]
class
as an attribute, use a class selector class
作为属性,使用类选择器 form
there need to be a space between form
and :not
, otherwise you will only select all forms without .inactive class
form
的元素,所以必须在form
和:not
之间留一个空格,否则,您将只选择all forms without .inactive class
This would be a correct element selector: 这将是正确的元素选择器:
const inputData = $('form :not(.inactive)');
To use serializeArray
correctly, take a look at @TJCrowder's answer! 要正确使用
serializeArray
,请查看@TJCrowder的答案!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.