$(this).html(); 输出的内容有点疑惑,求JS大神解答~谢过

$(this).html(); 输出的内容有点疑惑,求JS大神解答~谢过,第1张

修改JS为

$(document).ready(function(){

    $("#menu_id ul ul").css("display","block")

    $("#menu_id ul ul ul li a").click(function(){

        console.log($(this).html())

    })

})

$this只是个自定义的变量

$(this)是将当前don对象转换成jquery对象 ;

一般定义jquery变量习惯$开头,提高可读性而已。

$(this)是把DOM对象封装成jquery对象,其相当于一个集合。

用法如下:

<a href="http://IP/q/1010000000125418" target="_blank" data-id="1010000000125418">jQuery</a>

$('a').click(function(){

this.innerHTM==$(this).html()=='jQuery'//三者是一样的.

this.getAttribute('href')==this.href==$(this).attr('href')//三者是一样的

this.getAttribute('target')==this.target==$(this).attr('target')//三者是一样的

this.getAttribute('data-id')==$(this).attr('data-id')//二者是一样的

})


欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/zaji/8194657.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-04-14
下一篇 2023-04-14

发表评论

登录后才能评论

评论列表(0条)

保存