Javascript 当我的弹出窗口关闭时,如何不刷新页面?

Javascript 当我的弹出窗口关闭时,如何不刷新页面?,javascript,popup,page-refresh,Javascript,Popup,Page Refresh,因此,当单击链接时,我在页面上有一个非常简单的弹出窗口,但当我单击关闭按钮时,它将刷新页面。这很糟糕,因为我把它放在一组Ajax选项卡中,所以在刷新时,它会返回到tab1,而不是停留在tab3上。我知道有一个函数可以让父页面刷新,所以一定有一个函数可以不刷新吗?谢谢 这是我的JS $(document).ready(function(){ // show popup when you click on the link $('.show-popup').click(functio

因此,当单击链接时,我在页面上有一个非常简单的弹出窗口,但当我单击关闭按钮时,它将刷新页面。这很糟糕,因为我把它放在一组Ajax选项卡中,所以在刷新时,它会返回到tab1,而不是停留在tab3上。我知道有一个函数可以让父页面刷新,所以一定有一个函数可以不刷新吗?谢谢

这是我的JS

$(document).ready(function(){
    // show popup when you click on the link
    $('.show-popup').click(function(event){
        event.preventDefault(); // disable normal link function so that it doesn't refresh the page
        var docHeight = $(document).height();
        var docWidth = $(document).width(); //grab the height of the page
        $('.overlay-bg').show().css(); //display your popup and set height to the page height
        $('.overlay-content').css({'top': scrollTop+20+'px'}); //set the content 20px from the window top
    });

    // hide popup when user clicks on close button
    $('.close-btn').click(function(){
        $('.overlay-bg').hide(); // hide the overlay
    });

    // hides the popup if user clicks anywhere outside the container
    $('.overlay-bg').click(function(){
        $('.overlay-bg').hide();
    })
    // prevents the overlay from closing if user clicks inside the popup overlay
    $('.overlay-content').click(function(){
        return false;
    });

}))

我猜您的close dom包含一个链接。在close处理程序中,只需添加事件参数并防止默认值,就像其他单击一样

请参阅下面更新的关闭功能

$('.close-btn').click(function(evt) {
    evt.preventDefault();
    $('.overlay-bg').hide(); 
 });

嗯?对不起,我不太明白,我不擅长JS。这是关闭按钮链接,我用一个例子更新了我的答案。基本上,当您使用a标记时,它是一个链接,除非您捕获单击事件并阻止它尝试通过preventDefault功能导航到href,否则浏览器将始终重新加载。