Javascript 按键上的Jquery触发器
我正在使用wordpress作为cms 我编写了一个代码,当我按下左键时,它会运行like()函数 我尝试在like()函数中触发.love 但它不起作用 这是我的密码Javascript 按键上的Jquery触发器,javascript,jquery,Javascript,Jquery,我正在使用wordpress作为cms 我编写了一个代码,当我按下左键时,它会运行like()函数 我尝试在like()函数中触发.love 但它不起作用 这是我的密码 var h2top = 0; function like(){ scrollTop = jQuery(window).scrollTop(); jQuery('.container .post').each(function(i, h2){ /* loop through article headings */
var h2top = 0;
function like(){
scrollTop = jQuery(window).scrollTop();
jQuery('.container .post').each(function(i, h2){ /* loop through article headings */
h2top = jQuery(h2).offset().top ; /* get article heading top */
if (scrollTop<h2top-19) { /* compare if document is below heading */
alert("Ram");
jQuery(this).find('.love').trigger( "click" );
return false; /* exit function */
}
});
}
只需使用alert()检查代码是否正在运行
$(document).keyup(function(e) {
alert (1);
// use event.which instead of keyCode
});
而不是
$(document.documentElement).keyup(function (event) {
其他错误,在jQuery(this)行的like函数中。find('.love')。trigger(“click”)代码>
此
不是jQuery上下文,必须使用$(此)
类似
jQuery($(this)).find('.love').trigger( "click" );
示例(更新)
我想你看错问题了。。如果我使用.html()而不是触发器,它会工作
jQuery($(this)).find('.love').trigger( "click" );