jquery - on(鼠标移入移除)中$(this).$(.className)提示$(...).$ is not a function
本文介绍了jquery - on(鼠标移入移除)中$(this).$(.className)提示$(...).$ is not a function的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
问 题
这一段是成立且无报错
course_list.on('mouseover mouseout','li', function (e) {
if (e.type === "mouseover") {
this.getElementsByClassName('course_hover')[0].style.display = 'block';
} else if (e.type === "mouseout") {
this.getElementsByClassName('course_hover')[0].style.display = 'none';
}
})
但是改为$(this).$(.className)[0].style.display = 'block';
提示$(...).$ is not a function
以及为啥不能this.getElementsByClassName('course_hover')[0].css('dispaly', 'block')
这样写?
目的是鼠标移入一个元素,然后一个浮层在其上方显示出来。
解决方案
你去翻翻api
$(this).$(.className)
有find
有children
。哪有.$
这种用法?this.getElementsByClassName('course_hover')[0].css('dispaly', 'block')
不能这么写是因为.css
这种方法是jquery对象的方法,你用索引[0]
取出来的是原生dom对象,不存在这个方法。具体去搜jquery对象和dom对象的区别
。
这篇关于jquery - on(鼠标移入移除)中$(this).$(.className)提示$(...).$ is not a function的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文