为同一文本

时间:2018-02-08 04:31:19

标签: javascript jquery

我在使用表单时遇到问题。我想制作1个表格可以使用2个不同的文字使用药片标签。我使用JQuery来实现它。如果我选择药片标签Cash In我想显示文本Cash In in Cash In。如果我选择药片标签Cash Out我想显示文件Cash Out in Cash Out

html:

 <div role="tabpanel" class="tabcontent tab-pane">
                    <div class="tabNavigator">
                        <ul class="nav nav-pills" role="pilllist">
                            <li role="presentation" class="active">
                                <a href="" class="headerCash" aria-controls="home" role="pill" data-toggle="pill">Cash In</a>
                            </li>
                            <li role="presentation" class="">
                                <a href="" class="headerCash" aria-controls="home" role="pill" data-toggle="pill">Cash Out</a>
                            </li>
                        </ul>
                        <br>
                        <div class="tab-content">
                            <div role="pillpanel" class="tab-pane active">
                                <div class="panel panel-default">
                                    <div class="panel-body">
                                            <fieldset>
                                                <legend class="panelCashIn">Cash In</legend><legend class="panelCashOut">Cash Out</legend>
                                            </fieldset>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>

JQuery:

function getActive(){
        var activeCash = false;
        $('.headerCash').each(function(){
            if($(this).parent().hasClass('active')){
                $('.panelCashIn').show();
            }else if($(this).parent().hasClass('active')){
                $('.panelCashOut').show();
            }
        });
        return activeCash;
    }

        var activeCash = getActive();

        $('.headerCash').click(function (e) {
            e.preventDefault();
            $(this).tab('show');
        });

如果我选择丸标签现金或现金,如何创建不同的JQuery?

1 个答案:

答案 0 :(得分:0)

这就是你可以创建一个能满足这两种药片的单一形式的方法。你不需要任何jquery函数来处理这个问题。

       <form method="POST" >

        <ul class="nav nav-tabs">
          <li class="active"><a data-toggle="tab" href="#cashin">Cash In</a></li>
          <li><a data-toggle="tab" href="#cashout">Cash Out</a></li>
        </ul>

        <div class="tab-content">
          <div id="cashin" class="tab-pane fade in active">
            <fieldset>
                <legend class="panelCashIn">Cash In</legend>
            </fieldset>
              <input  type="number" step="0.01"  name="cashin" placeholder="Cash In" />
          </div>
          <div id="cashout" class="tab-pane fade">
            <fieldset>
                <legend class="panelCashIn">Cash Out</legend>
                <input  type="number" step="0.01"  name="cashout" placeholder="Cash Out" />
            </fieldset>
          </div>
        </div>

        <br/>   
        <input type="submit" value="Submit" >

       </form>