gpt4 book ai didi

jquery - elem.is (':checked' ) vs elem.prop ('checked' )

转载 作者:行者123 更新时间:2023-12-03 22:51:20 27 4
gpt4 key购买 nike

正如标题所示,elem.is(':checked') 之间有什么区别?和elem.prop('checked') .

我个人使用elem.is(':checked')因为函数is解释说我要返回 bool 值。

我什么时候应该选择其中之一?为什么?

最佳答案

答案基于This SO Question .

如果您使用的是 1.6.0 或更高版本,prop('checked') 是最直接的 jQuery 方法。 jQuery 不必解析和处理选择器来确定要做什么。

Note: The degree to which prop is more direct than is varies by browser. prop isn't just a direct check of a property, it does go through a couple of levels of indirection first; and is isn't necessarily hugely complex: On WebKit browsers, for instance, is can be fairly direct as WebKit provides a function to test whether an element matches a selector, and supports :checked natively; on Firefox (and, I suspect, IE), is results in a huge number of function calls as this seemingly-simple selector works its way through the guts of Sizzle.

测试结果: jQuery prop('checked') vs. is(':checked')

关于jquery - elem.is (':checked' ) vs elem.prop ('checked' ),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43464344/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com