未捕获的类型错误:对象 [object Object] 没有“on"方法 [英] Uncaught TypeError: Object [object Object] has no method 'on'
本文介绍了未捕获的类型错误:对象 [object Object] 没有“on"方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
谁能帮我解决这个问题?
Can anyone help me to figure this out ?
当我使用最新(或新)版本的 jQuery 时,下面的小脚本可以正常工作.但是,当我使用旧版本的 jQuery 时,我的脚本说 on
函数不存在.
When I use the latest (or a newish) version of jQuery, the small script below works fine. However, when I use older versions of jQuery, my script says that the on
function does not exist.
这是我的脚本,它不适用于旧版本的 jQuery:
Here is my script that doesn't work with older versions of jQuery:
$(document).ready(function () {
$(".theImage").on("click", function(){
// In the event clicked, find image, fade slowly to .01 opacity
$(this).find("img").fadeTo("slow", .01).end()
// Then, of siblings, find all images and fade slowly to 100% opacity
.siblings().find("img").fadeTo("slow", 1);
})
})
感谢任何形式的帮助.
推荐答案
必须使用bind
而不是 on
,如 on
仅在 jQuery 1.7 中引入.
You must use bind
instead of on
, as on
was only introduced in jQuery 1.7.
$(document).ready(function () {
$(".theImage").bind("click", function(){
// In the event clicked, find image, fade slowly to .01 opacity
$(this).find("img").fadeTo("slow", .01).end()
// Then, of siblings, find all images and fade slowly to 100% opacity
.siblings().find("img").fadeTo("slow", 1);
})
})
这篇关于未捕获的类型错误:对象 [object Object] 没有“on"方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文