Pau*_*aul 1 javascript jquery this
为什么在这个函数中返回"this":
(function($) {
$.fn.menumaker = function(options) {
var cssmenu = $(this), settings = $.extend({
title: "Menu",
format: "dropdown",
sticky: false
}, options);
return this.each(function() {
Run Code Online (Sandbox Code Playgroud)
this是"DOM元素"?如果我们想要使用函数的内容,为什么不引用$(this)使用我们所针对的元素,而不是this?
谢谢
jQuery方法(属性$.fn)不像jQuery事件处理程序回调.值this是jQuery对象本身,而不是DOM元素.
该$.fn对象是jQuery实例的原型对象,因此当您创建一个jQuery对象时
var jq = $(something);
Run Code Online (Sandbox Code Playgroud)
然后调用jQuery方法:
jq.whatever();
Run Code Online (Sandbox Code Playgroud)
thisJavaScript 的自然规则确定whatever()将使用jQuery对象作为值来调用this.
| 归档时间: |
|
| 查看次数: |
59 次 |
| 最近记录: |