我很难理解 jQuery 的 $.method()
和 $(selector).method
之间的区别。
$.method()
实际适用于 DOM 中的哪些元素?如果有人能帮助解释这两种说法之间的区别,我们将不胜感激!
最佳答案
$()
需要一个选择器来获取元素并将其返回到链中。而 $.
是一个普通方法,可以使用不链接 DOM 元素的方法。
以此为例:
// Will trim the current string - returns string
$.trim(' string ')
// Returns the current element in the DOM ready for chaining, i.e. $().remove
$('#id')
关于jQuery $.method() 与 $(selector).method(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19281285/