繁体   English   中英

下拉框不断向上滚动

[英]Drop Down Box keeps scrolling up

我从早期的问题实现了这个到我的网站但由于某种原因在Firefox和IE上,下拉框自动向上滚动。 我无法弄清楚为什么!

只需点击“新闻Feed”,当框下拉时,它会自动下降。 它应该下降,如果我再次或在外面点击newfeed,它应该放弃。 但它并没有这样做,它只是回升。

我正在使用JavaScript。 这里发生了什么?

$('#bottom').click(function() {
    $('#content').slideDown();
});

$(document).click(function(e) {
    if (e.target.id !='bottom') {
        $('#content').slideUp();
    }
});

#bottom更改#bottom事件处理程序以防止click事件一直冒泡到document

//it is important to declare the `event` variable as a parameter of this anonymous function so it can be accessed inside the function
$('#bottom').click(function(event) {
    event.stopPropagation();
    $('#content').slideDown();
});

你的代码发生的事情是#bottom元素的事件处理程序被触发,然后点击document的事件处理程序触发,因为click事件冒泡DOM。 event.stopPropagation()将阻止事件冒泡。

event.stopPropagation()文档: http//api.jquery.com/event.stoppropagation/

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM