当你点击“href”链接时,我有这个jQuery使FadeOut平滑页面。我该怎么办jQuery不适用于特定元素?
我有一个电子商务,所以我有一个购物车,你可以看到你添加的产品。 (在线商店:www.backlabel.com)
您可以直接用产品顶部的“X”将其从购物车中删除。这个“X”具有“href”属性,所以页面加载jQuery和它的坏,因为整个页面重新加载。
我希望jQuery不能在“X”按钮上工作。我可以在此jQuery中使用额外的代码吗?
// delegate all clicks on "a" tag (links)
$(document).on("click", "a", function (event) {
// get the href attribute
var newUrl = $(this).attr("href");
// veryfy if the new url exists or is a hash
if (!newUrl || newUrl[0] === "#") {
// set that hash
location.hash = newUrl;
return;
}
// now, fadeout the html (whole page)
$("html").fadeOut(function() {
// when the animation is complete, set the new location
location = newUrl;
});
// prevent the default browser behavior.
return false;
});
防止默认浏览器行为使用event.preventDefault() – atul