jQuery fn命名空间 [英] jQuery fn namespace

查看:97
本文介绍了jQuery fn命名空间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在阅读有关jQuery $ .fn命名空间的信息,为了理解我正在阅读的内容,如果没有捷径,我想举一个完整命令的示例. 例如,

I'm reading about the jQuery $.fn namespace, and in order to understand what I'm reading, I would like an example of a complete command if no shortcuts were taken. For instance,

$('p').click(function() {
console.log('click');
});

这可以用.fn重写吗?详尽的语法是什么?

Could this be rewritten with .fn in it somewhere? What would be the exhaustive syntax?

jQuery('p',document).fn.click(function() {
window.console.log('click');
});

推荐答案

jQuery.fnjQuery.prototype的别名;这是标准的Javascript原型机制.
实际的jQuery 对象(实例)没有fn属性.

jQuery.fn is an alias for jQuery.prototype; it's the standard Javascript prototype mechanism.
Actual jQuery objects (instances) do not have an fn property.

您需要使用callapply调用这些函数,使this关键字成为您正在调用它们的对象.

You need to call the functions such that the this keyword is the object you're invoking them on, using call or apply.

例如:

jQuery.fn.click.call(jQuery('p',document), function() { ... })

这篇关于jQuery fn命名空间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆