如果链接以开头,如何禁用Javascript单击功能#

如果链接以开头,如何禁用Javascript单击功能#,javascript,html,Javascript,Html,除了以#开头的链接(如引导折叠、模式链接等)外,我如何在所有URL链接上运行此代码 $(function(){ $("a").click(function() { $(".se-pre-con").fadeOut("slow"); $(this).after("<div class='se-pre-con text-center pp500'><i class='fa fa-list fa-spin fa-5x fa-fw text-co

除了以
#
开头的链接(如引导折叠、模式链接等)外,我如何在所有URL链接上运行此代码

$(function(){
    $("a").click(function() {
        $(".se-pre-con").fadeOut("slow");
        $(this).after("<div class='se-pre-con text-center pp500'><i class='fa fa-list fa-spin fa-5x fa-fw text-color1'></i></div>").fadeIn(); 
    });
});
$(函数(){
$(“a”)。单击(函数(){
美元(“.se pre con”)。淡出(“缓慢”);
$(this).after(“”.fadeIn();
});
});

您只需检查第一个字符,确保它不是#

$(函数(){
$(“a”)。单击(函数(){
if($(this.attr(“href”).substr(0,1)!=“#”){
美元(“.se pre con”)。淡出(“缓慢”);
$(this).after(“”.fadeIn();
}
});
});

您可以在jquery中使用
not
选择器。例如:

$(函数(){
$(“a:not([href=”#“]))。单击(函数(e){
e、 预防默认值();
警惕(“你点击了我!”);
});
});
a{display:block}

只需使用CSS否定和前缀属性选择器:

$('a:not([href^=“#“])。单击(…)
$(function() {
  $("a").click(function() {
    if ($(this).attr("href").substr(0, 1) != "#") {
      $(".se-pre-con").fadeOut("slow");
      $(this).after("<div class='se-pre-con text-center pp500'><i class='fa fa-list fa-spin fa-5x fa-fw text-color1'></i></div>").fadeIn();
    }
  });

});