我的网页上有一些javascript代码正在将一些div加载到页面上.我还想为每个div添加onmouseenter和onmouseleave事件处理程序.我使用jquery添加这些处理程序,但我收到错误:
"对象[对象DOMWindow]的属性'$'不是函数"
我的代码看起来像这样,它在for循环中:
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' });
});
Run Code Online (Sandbox Code Playgroud)
有没有人有任何想法,为什么我得到这个错误,甚至错误意味着什么?