Javascript 如何在jquery中排除多个div
如何在此代码中排除多个div,而不仅仅是一个div:Javascript 如何在jquery中排除多个div,javascript,jquery,smooth-scrolling,Javascript,Jquery,Smooth Scrolling,如何在此代码中排除多个div,而不仅仅是一个div: $(function() { $('a[href*="#"]:not([href="#about"])').click(function() { if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'') && location.hostname == this.hostname) { var
$(function() {
$('a[href*="#"]:not([href="#about"])').click(function() {
if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'') && location.hostname == this.hostname) {
var target = $(this.hash);
target = target.length ? target : $('[name=' + this.hash.slice(1) +']');
if (target.length) {
$('html, body').animate({
scrollTop: target.offset().top
}, 1000);
return false;
}
}
});
});
您可以将项目添加为逗号分隔的值,如
:not([href=“#about”],[href=“#home”])
但是还有其他的方法,比如下面
$('a[href*="#"]').not('[href="#about"],[href="#home"]');
看起来我甚至不能从你的代码中排除一个div。请详细说明您的问题。我不知道如何在这行中添加更多元素:not([href=“#about”])
'a[href*=“#”]:not([href=“#about”],[href=“#somethingelse”])
<代码>如何排除更多div但您的代码针对的是锚。那么你的问题到底是什么呢?a:不([href=“#about”])
试试这个。div是如何涉及的?你正在选择一个锚…?谢谢你Rejith R Krishnan!