前端工具:MyCodepen】| 【W3School】| 【Bootstrap】| 【MarkDown】| 【正则表达式】| 【图标下载】| 【在线工具】| 【W3标准及兼容】| 【前端中文文档

jquery中onclick内$(this)指向

jquery中onclick=”fn”中$(this)所代表的对象

js方法

function qiehuan(){
        var src = $(this).attr(“data”);
        alert($(this));
        alert(src);
    }

html1

<div data=”123” class=”list-group” style=”margin-bottom: 0px;” onclick=”qiehuan()”>
    <a href=”#” class=”list-group-item”>123</a>
</div>

$(this)返回的是windows对象

html2

<div data=”123” class=”list-group” style=”margin-bottom: 0px;” onclick=”qiehuan.call(this)”>
    <a href=”#” class=”list-group-item”>123</a>
</div>

$(this)返回的是div对象

posted @ 2014-09-16 15:43  FuGardenia  阅读(925)  评论(0编辑  收藏  举报

关于我们

喜欢编程。
上大学四年,一直在探索。
最终走上前端工程师的不归路。


我的微博:

@WOOEOOBOO

GitHub:

@FuGardenia

关注我们

微信号:MoveClouds
移动互联网,云前端信息传播自媒体。

Simple is beauty,Less is more.

简而美,少即多。