$(this)如何在jQuery中工作 [英] How does $(this) work in jQuery

查看:82
本文介绍了$(this)如何在jQuery中工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

jQuery标记 $(this)如何正确工作?我知道如何使用它,但jQuery如何知道哪个元素是活动的?什么是获取当前项目的原始Javascript标记,还是只有jQuery?

解决方案

是一个简单的javascript(DOM)对象,
$(this)会将对象转换成jQuery对象。 p>

jQuery不需要'知道'这个是什么,它不会以特殊的方式对待它,在$
$ p $ var myHeaderDiv =报头');
$ myHeaderDiv = $(myheaderDiv); //只是一个变量转换成jQuery对象,就像这样。


How does the jQuery tag $(this) exactly work? I know how to use it, but how does jQuery know which element is 'active'? And what is the original Javascript tag for getting the current item, or is it jQuery only?

解决方案

The this is a simple javascript (DOM) object, $(this) will turn the object into a jQuery object.

jQuery doesn't need to 'know' what this is, it doesn't treat this in a special way, no other than myHeaderDiv in

var myHeaderDiv = document.getElementById('header'); 
$myHeaderDiv = $(myheaderDiv); //just a variable transformed into jQuery object, as with this.

这篇关于$(this)如何在jQuery中工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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