[英]Neither .on or .live functions are recognized
I am so frustrated right now. 我现在很沮丧。 I have been trying for the past half hour to get event delegation
to work. 过去半小时我一直试图让event delegation
工作。 I tried using .on
and Chrome told me that it wasn't a function. 我尝试使用.on
,Chrome告诉我这不是一个功能。
I searched this question 我搜索了这个问题
$(...).on is not a function - jQuery Error $(...)。on不是函数 - jQuery Error
and thought it was because I was using an earlier version of JQuery. 并认为这是因为我使用的是早期版本的JQuery。 Because of that, I decided to include the latest version of JQuery from the Google Developer's website 因此,我决定从Google Developer的网站上加入最新版本的JQuery
https://developers.google.com/speed/libraries/ https://developers.google.com/speed/libraries/
Here's what I included at the end of my body
tag 这是我在body
标签末尾包含的内容
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
I thought that would solve the problem 我认为这样可以解决问题
If I click on the link under View Source (Ctrl + u)
and click on the JQuery file, I get source code, which leads me to believe it was loaded properly. 如果我单击View Source (Ctrl + u)
下的链接并单击JQuery文件,我会得到源代码,这使我相信它已正确加载。
I also tried to use the .live
function and found out that wasn't a function either. 我也尝试使用.live
函数,发现它也不是函数。 There's almost no chance I have a syntax error either 我几乎没有机会出现语法错误
$("td > a")[0].on("click", function() { alert('hi') })
Yet, I get the following output from the console 然而,我从控制台获得以下输出
Uncaught TypeError: $(...)[0].on is not a function at :2:16 at Object.InjectedScript._evaluateOn (:895:140) at Object.InjectedScript._evaluateAndWrap (:828:34) at Object.InjectedScript.evaluate (:694:21) 未捕获的TypeError:$(...)[0] .on不是函数at:2:16 at Object.InjectedScript._evaluateOn(:895:140)at Object.InjectedScript._evaluateAndWrap(:828:34)at Object。 InjectedScript.evaluate(:694:21)
I also tried copying and pasting the minified JQuery code into a JavaScript file, and including that way, but that also failed. 我还尝试将缩小的JQuery代码复制并粘贴到JavaScript文件中,包括这种方式,但也失败了。
Is it an issue with the Content Distribution Network(CDN)
or a problem with the version itself? 是Content Distribution Network(CDN)
的问题还是版本本身的问题?
I know that JQuery 2
only supports modern browsers, but I am using Google Chrome
. 我知道JQuery 2
仅支持现代浏览器,但我使用的是Google Chrome
。 I can not understand what the problem is. 我无法理解问题所在。
Has anyone else ran into this problem before? 有没有其他人遇到过这个问题? Help or advice is most appreciated. 非常感谢帮助或建议。
Edit: 编辑:
`jquery.fn.jquery` returns `2.1.3`
You're attempting to apply a jQuery method to a raw DOM object. 您正在尝试将jQuery方法应用于原始DOM对象。 With the index specified you no longer have a jQuery object selected. 指定索引后,您不再选择jQuery对象。
Also, the way you've structured your on()
function doesn't employ event delegation. 此外,您构建on()
函数的方式不使用事件委派。 Try this: 尝试这个:
$(document).on("td > a:eq(0)", "click", function() { alert('hi') });
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.