Jquery不在twig模板中工作

时间:2016-03-12 13:50:48

标签: jquery html twig

我使用twig模板管理器渲染显示引导标签导航的页面,我已经证明了许多代码,但似乎没有人工作,并且因为看到检查员显然链接没有抓住jquery事件而无法工作,我我已经在一个简单的html页面中尝试了所有代码并且工作得很好,这是我探测的最后一件事(w3school示例):

{% block tabs %}

    <div class="container">
    <h2>Dynamic Tabs with jQuery</h2>

    <p>Click on the Tabs to display the active and previous tab.</p>
    <ul class="nav nav-tabs">
        <li class="active"><a href="#home">Home</a></li>
        <li><a href="#menu1">Menu 1</a></li>
        <li><a href="#menu2">Menu 2</a></li>
        <li><a href="#menu3">Menu 3</a></li>
    </ul>

    <div class="tab-content">
         <div id="first" class="tab-pane fade in active">
             <h3>HOME</h3>
             <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.</p>
         </div>
         <div id="menu1" class="tab-pane fade">
             <h3>Menu 1</h3>
             <p>Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.</p>
         </div>
         <div id="menu2" class="tab-pane fade">
             <h3>Menu 2</h3>
             <p>Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium, totam rem aperiam.</p>
         </div>
         <div id="menu3" class="tab-pane fade">
             <h3>Menu 3</h3>
             <p>Eaque ipsa quae ab illo inventore veritatis et quasi architecto beatae vitae dicta sunt explicabo.</p>
         </div>
     </div>
    <hr>
    <p class="act"><b>Active Tab</b>: <span></span></p>
    <p class="prev"><b>Previous Tab</b>: <span></span></p>
   </div>

    <script>
    $(document).ready(function(){
        $(".nav-tabs a").click(function(){
            $(this).tab('show');
        });
        $('.nav-tabs a').on('shown.bs.tab', function(event){
            var x = $(event.target).text();         // active tab
            var y = $(event.relatedTarget).text();  // previous tab
            console.log(x);
            console.log('y');

            $(".act span").text(x);
            $(".prev span").text(y);
        });
    });
    </script>

{% endblock tabs %}

我希望有人可以帮助我,谢谢!

0 个答案:

没有答案