onclick和href一起不起作用

onclick and href together not working

本文关键字:不起作用 一起 href onclick      更新时间:2023-09-26

我正在创建一个html页面,其中我在点击选项卡上有三个选项卡,我想激活它,还想转到其他页面这是我的代码

<div class="col-sm-3 text-center sprtr-1">
      <a class="tab-link" href="#events?eventType=Movies&industry={{selectedIndustry.name}}" onclick="return theFunction();" i18n="EVENT.MOVIES"><span class="glyphicon glyphicon-facetime-video"></span> MOVIES</a>
    </div>
    <div class="col-sm-3 text-center sprtr-1">
      <a class="tab-link" href="#events?eventType=Performance&industry={{selectedIndustry.name}}" i18n="EVENT.PERFORMANCES"><span class="glyphicon glyphicon-leaf"></span> PERFORMANCES</a>
    </div>
    <div class="col-sm-3 text-center sprtr-1">
      <a class="tab-link" href="#events?eventType=WorkShops&industry={{selectedIndustry.name}}" i18n="EVENT.WORKSHOPS"><span class="glyphicon glyphicon-gift"></span> WORKSHO PS</a>
    </div>

这是我的脚本

<script type="text/javascript">
     function theFunction() {
         alert("dfsdf");
       if(!$(this).hasClass("active")){
                 $(".active").removeClass("active");
                 $(this).addClass("active");
        }else{
            return false;//this prevents flicker
       }
     }
</script>

有人能帮我处理这个吗

你可以试试这个:

$(document).ready(function(){
    $('.tab-link').click(function(){
            alert("dfsdf");
           if(!$(this).hasClass("active")){
                     $(".active").removeClass("active");
                     $(this).addClass("active");
            }else{
                return false;//this prevents flicker
           }
    });
});
onclick="theFunction();"

您不需要return语句。

添加此target="_blank">锚定标签

<a href="#" onclick="someFuntion()" target="_blank">Text</a>
<a class="tab-link" href="#events?eventType=Movies&industry={{selectedIndustry.name}}" onclick="theFunction(); return true" i18n="EVENT.MOVIES"><span class="glyphicon glyphicon-facetime-video"></span> MOVIES</a>

它将为你工作

   <a class="tab-link" href="#events?eventType=Movies&industry={{selectedIndustry.name}}" onclick="return theFunction();" i18n="EVENT.MOVIES"><span class="glyphicon glyphicon-facetime-video"></span> MOVIES</a>
function theFunction(event) {
   event.preventDefault();
    alert("dfsdf");
   if(!$(this).hasClass("active")){
             $(".active").removeClass("active");
             $(this).addClass("active");
    }else{
        return false;//this prevents flicker
   }
  return true;
}