简体   繁体   English

JS函数在onclick事件中不可见

[英]JS function not visible in onclick event

Using ASP.NET + BootStrap 3 and trying to create tabs. 使用ASP.NET + BootStrap 3并尝试创建选项卡。 Everything works fine except that I want that fine border to appear around the currently active tab. 一切正常,除了我希望该细边框出现在当前活动的选项卡周围。 For this purpose I need to apply active class on that li (and remove active from other li elements). 为此,我需要在该li上应用active类(并从其他li元素中删除active )。 I'm trying to achieve that through the following simple JS function. 我正在尝试通过以下简单的JS函数实现这一目标。 But when I click a tab header, it tells me that the function activateTab() is not defined. 但是,当我单击选项卡标题时,它告诉我未定义函数activateTab() Any clues? 有什么线索吗?

<EditItemTemplate>
    <script type="text/javascript">
        function activateTab(tab) {
            $("#ItemTabs ul li").removeClass("active");
            $(tab).addClass("active");
        }
     </script>

    <div id="ItemTabs">
        <ul class="nav nav-tabs">
            <li><a href="#tab-Details" onclick="activateTab(this.parentElement);">Details</a></li>
            <li><a href="#tab-AdditionalInfo" onclick="activateTab(this.parentElement);">Additional Info</a></li>
            ...
        </ul>
    </div>
</EditItemTemplate>

NB: I'm not a seasoned web developer and may be reinventing the wheel here. 注意:我不是经验丰富的Web开发人员,可能在这里重新发明轮子。 Plz let me know if there is an easier way. 请让我知道是否有更简单的方法。

when javascript file is having some compile error , that time it gives these kind of problem. 当javascript文件出现一些编译错误时,这时就会出现此类问题。 You can try with this : 您可以尝试以下方法:

from $("#ItemTabs ul li").removeClass("active") TO this 
      $('div#ItemTabs > ul li').removeClass('active')

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM