Javascript 手动传递此onClick事件
如何从其他函数手动传递“this”值 jQueryJavascript 手动传递此onClick事件,javascript,jquery,Javascript,Jquery,如何从其他函数手动传递“this”值 jQuery $('#divName ul li a').click(function() { $(this).addClass('active'); }); $(window).scroll(function() { //for condition a //the value of this will a //for condition b //the value of this will be }); 选中此
$('#divName ul li a').click(function() {
$(this).addClass('active');
});
$(window).scroll(function() {
//for condition a
//the value of this will a
//for condition b
//the value of this will be
});
选中此项您是否尝试实现单击和滚动功能?将滚动处理程序放在单击处理程序中
$("div").click(function(e) {
var target = this;
$(window).on("scroll.clickScroll", function(e) {
// Use "target" as the reference to what was clicked on.
}
}
请注意,当单击停止时,必须删除处理程序,如下所示:
$(window).off("scroll.clickScroll");
我在这里使用事件名称间距来区分普通窗口滚动和专门的单击滚动
$(window).off("scroll.clickScroll");