简体   繁体   English

.load导致Internet Explorer中的页面刷新?

[英].load causing total page refresh in Internet Explorer?

So I've got a simple site with a menu bar and a content area. 因此,我有一个带有菜单栏和内容区域的简单站点。 When I click one of the buttons in the menu bar, it's supposed to do a quick fadeIn transition on a graphical element of the content area, and load external content into a div. 当我单击菜单栏中的按钮之一时,应该在内容区域的图形元素上进行快速的fadeIn过渡,并将外部内容加载到div中。

$("#button1").click(function(){
$(".contentdivs").fadeIn(1000);
$(".content").load("external.html");
});

This works exactly as intended in Chrome, Safari and Firefox, but not in Internet Explorer. 这完全可以在Chrome,Safari和Firefox中正常运行,但不能在Internet Explorer中运行。

In Explorer, clicking #button1 will trigger the .Fadein and the .load (I can see the transition and the external data render very briefly) but then the entire page refreshes, and the external content gets unloaded. 在资源管理器中,单击#button1将触发.Fadein和.load(我可以非常短暂地看到过渡和外部数据渲染),但是随后整个页面刷新,并且外部内容被卸载。

Any ideas why this is happening, and how to fix it? 有什么想法为什么会发生这种情况,以及如何解决?

Is the button an anchor tag? 按钮是锚标记吗? You probably need to prevent the click event's default action and stop the event from bubbling in case there's an anchor parent to the button: 您可能需要阻止click事件的默认操作,并阻止该事件冒泡,以防该按钮有锚父:

$("#button1").click(function(e){
    e.preventDefault();
    e.stopPropagation();
    $(".contentdivs").fadeIn(1000);
    $(".content").load("external.html");
});

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

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