简体   繁体   中英

How to use Semantic-ui multiple tabs with Python-Flask?

I want to use Jinjia render template.There are many Semantic-ui tabs on this page. It's templates code.

{% extends "/base.html" %}

{% block content %}
<div class="ui centered cards">
{% for p in plan %}
<div class="ui card">
    <div class="ui segment" style="padding:0px;">
        <div class="ui top attached tabular menu" id="{{p,id}}">
            <a class="item active" data-tab="monthly">monthly</a>
            <a class="item" data-tab="quarterly">quarterly</a>
            <a class="item" data-tab="annualy">annualy</a>
            <a class="item" data-tab="yearly">yearly</a>
        </div>
        <div class="ui bottom attached tab segment active" data-tab="monthly">
          {{p.monthly}}{{p.currency}}
        </div>
        <div class="ui bottom attached tab segment" data-tab="quarterly">
          {{p.monthly}}{{p.currency}}
        </div>
        <div class="ui bottom attached tab segment" data-tab="annualy">
          {{p.monthly}}{{p.currency}}
        </div>
        <div class="ui bottom attached tab segment" data-tab="yearly">
          {{p.monthly}}{{p.currency}}
        </div>
    </div>
</div>
{%endfor%}
</div>
</body>
<script>
$('.menu .item')
  .tab()
;
</script>
</html>
{% endblock %}

PS:I have introduced semanticui in base.html

{% for p in plan %}:When there are multiple targets to traverse, the tabs of the rendered page cannot be switched individually.

I read the jquery and Semantiv-ui documents carefully. Then I carefully experimented and found out how TAB works. Then wrote the following javascript code. I successfully implemented a separate switch for TAB.

<script>
$(document).ready(function(){
  $(".menu .item").click(function(){
    var datatab = $(this).attr("data-tab");
    $(this).closest("div").children(".active").removeClass("active");
    $(this).addClass("active");
    $(this).closest("div").siblings(".active").removeClass("active");
    $(this).closest("div").siblings("[data-tab="+datatab+"]").addClass("active");
});
});
</script>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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