我正在尝试使用jQuery将函数绑定到这些事件:
$("#cmplist tr").bind('onmouseover', function(){
console.log('1');
});
$("#cmplist tr").bind('onmouseout', function(){
console.log('2');
});
$("#cmplist tr").bind('click', function(){
console.log('3');
});
然而,它们似乎都不起作用。我有理由相信我的选择器是正确的,因为当我进入控制台$("#cmplist tr")
时它会返回:
[tr, tr#survey3, tr#survey20, tr#survey22, tr#survey26, tr#survey28, tr#survey29, tr#survey30, tr#survey33, tr#survey34, tr#survey6, tr#survey19, tr#survey14, tr#survey32, tr#sweepstakes5, tr#sweepstakes9, tr#coupons5, tr#freesample4, tr#freesample5, tr#freesample6, tr#freesample7, tr#gifts3, tr#gifts4, tr#polls2, tr#polls5, tr#polls6, tr#quiz8, tr#trivia4, tr#photo6, tr#photo10, tr#photo11, tr#photo12, tr#photo13, tr#photo15, tr#photo16, tr#photo17, tr#video4, tr#iframe2, tr#iframe4]
我是否遗漏了有关jQuery事件如何运作的内容?
答案 0 :(得分:8)
从您的活动名称中删除“打开”。此外,我认为现在要做的事情是使用“mouseenter”和“mouseleave”与jQuery事件处理程序。这些事件由图书馆“标准化”,以便在面对古怪的浏览器行为时使一切更加可靠。
另外,请确保在“准备好”的处理程序中进行绑定,除非您确信自己有另一种同样有效的解决方案:
$(function() {
// your event binding stuff here
});
答案 1 :(得分:2)
试试这个:
$(function(){
$("#cmplist tr").bind('mouseover', function(){
console.log('1');
});
$("#cmplist tr").bind('mouseout', function(){
console.log('2');
});
$("#cmplist tr").bind('click', function(){
console.log('3');
});
});