jQuery,Uncaught TypeError [英] jQuery, Uncaught TypeError
问题描述
我的网页上有一些javascript代码正在将一些div加载到页面上。我还想为每个div添加onmouseenter和onmouseleave事件处理程序。我使用jquery添加这些处理程序,但是我收到错误:
I have some javascript code on my webpage that is loading some divs onto the page. I also want to add onmouseenter, and onmouseleave event handlers to each div. I am using jquery to add these handlers, but i get the error:
对象[对象DOMWindow]的属性'$'不是函数
"Property '$' of object [object DOMWindow] is not a function"
我的代码看起来像这样,它在for循环中:
My code looks like this, it is in a for loop:
var newItem = document.createElement('div');
newItem.innerHTML = results[i];
newItem.setAttribute("id", "resultDiv_" + i.toString());
dropDown.appendChild(newItem);
//Error on next line...
$("resultDiv_" + i.toString()).bind("mouseenter", function() {
$("resultDiv_" + i.toString()).css({ 'background-color': 'blue' });
});
有没有人知道为什么我会收到此错误,甚至错误意味着什么?
Does anyone have any ideas why i am getting this error, or even what the error means?
推荐答案
你确定jQuery已正确加载吗?它可能与另一个JavaScript库发生冲突吗?
Are you sure that jQuery is properly loaded? Could it be a conflict with another javascript library?
这篇关于jQuery,Uncaught TypeError的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!