$('a').click(function(e) {
e.preventDefault();
newLocation = this.href;
$('#monster').fadeOut('slow', newpage);
});
function newpage() {
window.location = newLocation;
}
我正在使用以下代码进行页面转换的淡出效果,每当我们点击任何链接时(" a"),我想删除带有id"的1个链接的此效果#flip",我该怎么做?
答案 0 :(得分:1)
您可以使用jQuery's :not
selector。此外,我已将您的click
函数切换为on
事件处理程序,与速记click
相比,它更灵活。个人喜好。
<强>的jQuery 强>
$('a:not("#flip")').on('click', function(event) {
event.preventDefault();
// newLocation = this.href;
// $('#monster').fadeOut('slow', newpage);
alert('Only link tags without the #flip id should show this');
});
var newpage = function() {
window.location = newLocation;
}
<强> HTML 强>
<a href='#'>This link will work</a>
<a href='#'>This link will work</a>
<a href='#' id='flip'>This link will <b>not</b> work</a>