Cas*_*ynn 0 javascript jquery events bind
我正在尝试使用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');
});
Run Code Online (Sandbox Code Playgroud)
但是它们似乎都没有用.我有理由相信我的选择器是正确的,因为当我进入控制台时$("#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]
Run Code Online (Sandbox Code Playgroud)
我错过了有关jQuery事件如何工作的内容吗?
从事件名称中删除"打开".此外,我认为现在要做的事情是使用"mouseenter"和"mouseleave"与jQuery事件处理程序.这些事件被库"标准化",以便在面对古怪的浏览器行为时使一切更加可靠.
另外,确保你在"准备好"的处理程序中进行绑定,除非你确信你有一个替代的,同样有效的解决方案:
$(function() {
// your event binding stuff here
});
Run Code Online (Sandbox Code Playgroud)