gpt4 book ai didi

javascript - jQuery:$(this) 与 this.$()

转载 作者:行者123 更新时间:2023-12-03 21:48:20 24 4
gpt4 key购买 nike

在 Ember.js 的 docs 中,他们有一个具有以下语法的 jQuery 代码片段:

this.$().button();

此代码片段是否只是将 this 转换为 jQuery 对象,以便可以在其上调用 jQuery UI .button() 函数?

这个片段是否相同?

$(this).button();

最佳答案

source code解释如下:

/**
Returns a jQuery object for this view's element. If you pass in a selector
string, this method will return a jQuery object, using the current element
as its buffer.

For example, calling `view.$('li')` will return a jQuery object containing
all of the `li` elements inside the DOM element of this view.

@param {String} [selector] a jQuery-compatible selector string
@returns {Ember.CoreQuery} the CoreQuery object for the DOM node
*/
$: function(sel) {
return this.invokeForState('$', sel);
},

所以回答你的问题:不,它与 $(this) 不同,后者会将 ember View 实例包装在 jQuery 对象中......

关于javascript - jQuery:$(this) 与 this.$(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11091148/

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