我使用这段代码用jquery加载一些链接。它适用于所有<a></a>
。我如何从这个脚本中跳过一些<a></a>
?
$("a").on("click", function(e) {
e.preventDefault();
var sectionID = '#'+ $(this).data("section");
$("#content section:visible").fadeOut('normal');
$(sectionID).fadeIn('normal');
});
});
有两种方法可以达到你的目标。
1。选择链接:
<a href="#" class="special test foo">Function will execute</a>
<a href="#" class="special">Function will execute</a>
<a href="#" class="special">Function will execute</a>
<a href="#" class="bar special">Function will execute</a>
<a href="#">Function will not execute</a>
<a href="#" class="foo">Function will not execute</a>
JS:
$("a.special").on("click", function(e) {
e.preventDefault();
var sectionID = '#'+ $(this).data("section");
$("#content section:visible").fadeOut('normal');
$(sectionID).fadeIn('normal');
});
});
2。选择退出链接:
<a href="#" class="noShow">Function will not execute</a>
<a href="#" class="noShow test">Function will not execute</a>
<a href="#">Function will execute</a>
<a href="#" class="bar">Function will execute</a>
JS:
$("a").not('.noShow').on("click", function(e) {
e.preventDefault();
var sectionID = '#'+ $(this).data("section");
$("#content section:visible").fadeOut('normal');
$(sectionID).fadeIn('normal');
});
});