未捕获的TypeError:对象[object Object]没有方法'on' [英] Uncaught TypeError: Object [object Object] has no method 'on'
本文介绍了未捕获的TypeError:对象[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);
})
})
感谢您提供任何帮助.
推荐答案
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);
})
})
这篇关于未捕获的TypeError:对象[object Object]没有方法'on'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文