如何提交非活动标签Jquery的值

时间:2015-08-23 18:31:07

标签: javascript jquery twitter-bootstrap jquery-ui bootstrap-tabs

我使用JQuery Tabs提交动态表单字段,但问题是它只保留提交最后一个标签值,因为它检查哪个标签处于活动状态,哪个不是这样,因为它看到最后一个标签处于活动状态,因此它发布了该值的值标签只有其他类似于1,2,3等。

这是我正在使用的JQuery代码:

$('#rootwizard').bootstrapWizard({onTabShow: function (tab, navigation, index) {
            var $total = navigation.find('li').length;
            var $current = index + 1;
            var $percent = ($current / $total) * 100;
            $('#rootwizard').find('.bar').css({width: $percent + '%'});
            // If it's the last tab then hide the last button and show the finish instead
            if ($current >= $total) {
                $('#rootwizard').find('.pager .next').hide();
                $('#rootwizard').find('.pager .finish').show();
                $('#rootwizard').find('.pager .finish').removeClass('disabled');
            } else {
                $('#rootwizard').find('.pager .next').show();
                $('#rootwizard').find('.pager .finish').hide();
            }
        }});
    $('#rootwizard .finish').click(function () {
        alert('Finished!, Starting over!');
        //$('#rootwizard').find("a[href*='tab1']").trigger('click');
        $("#mealForm").submit();
    });

mealForm 是包含所有标签数据的表单ID,但仅发布最后一个标签/活动标签值并非所有标签。

以下是使用PHP生成动态标签和动态表单的HTML代码,但它只提交活动标签数据而不是全部标签数据。

HTML:

 <div id="rootwizard">
                <div class="navbar">
                    <div class="navbar-inner">
                        <div class="container">
                            <ul>
                                <?php
                                for ($counter = 1; $counter <= $_POST['meal_numbers']; $counter++) {
                                    ?>
                                    <li><a href="#tab<?php echo $counter; ?>" data-toggle="tab">Meal <?php echo $counter; ?></a></li>
                                <?php } ?>
                            </ul>
                        </div>
                    </div>
                </div>
                <div id="bar" class="progress progress-striped active">
                    <div class="bar"></div>
                </div>
                <div class="tab-content">
                    <?php
                    for ($counter = 1; $counter <= $_POST['meal_numbers']; $counter++) {
                        ?>
                        <div class="tab-pane" id="tab<?php echo $counter; ?>">
                            <form action="process/adminProcess.php?page=addClientMealData" method="post" id="mealForm" class="form-horizontal">
                                <fieldset>
                                    <?php
                                    $mealData = 1;
                                    $QuerySet = $objadminViewFunctions->viewAllFoodCategoryData();
                                    while ($RecordSet = $QuerySet->fetch_object()) {
                                        ?>
                                        <div class="control-group">
                                            <label class="control-label" for="focusedInput"><?php echo $RecordSet->food_name . ' ' . $RecordSet->food_gram . ' (grams)'; ?></label>
                                            <div class="controls">
                                                <?php //print $objadminViewFunctions->viewFoodSourcesDropdownForAddPg($RecordSet->id); ?>
                                                <input class="input-xlarge focused" id="focusedInput" name="mealData[<?php echo $counter; ?>][<?php echo $mealData; ?>][macro_ratio]" type="text">
                                                <input type="hidden" name="mealData[<?php echo $counter; ?>][<?php echo $mealData; ?>][foodCategoryId]" value="<?php echo $RecordSet->id; ?>">
                                            </div>
                                        </div>
                                        <?php
                                        $mealData++;
                                    }
                                    ?>
                                </fieldset>
                                <ul class="pager wizard">
                                    <li class="previous first" style="display:none;"><a href="javascript:void(0);">First</a></li>
                                    <li class="previous"><a href="javascript:void(0);">Previous</a></li>
                                    <li class="next last" style="display:none;"><a href="javascript:void(0);">Last</a></li>
                                    <li class="next"><a href="javascript:void(0);">Next</a></li>
                                    <!--<li class="next finish" style="display:none;"><a href="javascript:;">Finish</a></li>-->
                                    <button type="submit" class="btn btn-primary next finish" style="display:none;">Submit</button>
                                </ul>
                            </form>
                        </div>
                    <?php } ?>

                </div>  
            </div>

以上是HTML表单数据的输出:

<div id="rootwizard">
  <div class="navbar">
    <div class="navbar-inner">
      <div class="container">
        <ul>
          <li><a href="#tab1" data-toggle="tab">Meal 1</a></li>
          <li><a href="#tab2" data-toggle="tab">Meal 2</a></li>
        </ul>
      </div>
    </div>
  </div>
  <div id="bar" class="progress progress-striped active">
    <div class="bar"></div>
  </div>
  <div class="tab-content">
    <div class="tab-pane" id="tab1">
      <form action="process/adminProcess.php?page=addClientMealData" method="post" id="mealForm" class="form-horizontal">
        <fieldset>
          <div class="control-group">
            <label class="control-label" for="focusedInput">Protein 60 (grams)</label>
            <div class="controls">
              <input class="input-xlarge focused" id="focusedInput" name="mealData[1][1][macro_ratio]" type="text">
              <input type="hidden" name="mealData[1][1][foodCategoryId]" value="37">
            </div>
          </div>
          <div class="control-group">
            <label class="control-label" for="focusedInput">Protein 55 (grams)</label>
            <div class="controls">
              <input class="input-xlarge focused" id="focusedInput" name="mealData[1][2][macro_ratio]" type="text">
              <input type="hidden" name="mealData[1][2][foodCategoryId]" value="2">
            </div>
          </div>
          <div class="control-group">
            <label class="control-label" for="focusedInput">Protein 50 (grams)</label>
            <div class="controls">
              <input class="input-xlarge focused" id="focusedInput" name="mealData[1][3][macro_ratio]" type="text">
              <input type="hidden" name="mealData[1][3][foodCategoryId]" value="3">
            </div>
          </div>
          <div class="control-group">
            <label class="control-label" for="focusedInput">Protein 45 (grams)</label>
            <div class="controls">
              <input class="input-xlarge focused" id="focusedInput" name="mealData[1][4][macro_ratio]" type="text">
              <input type="hidden" name="mealData[1][4][foodCategoryId]" value="4">
            </div>
          </div>
          <div class="control-group">
            <label class="control-label" for="focusedInput">Protein 40 (grams)</label>
            <div class="controls">
              <input class="input-xlarge focused" id="focusedInput" name="mealData[1][5][macro_ratio]" type="text">
              <input type="hidden" name="mealData[1][5][foodCategoryId]" value="5">
            </div>
          </div>
          <div class="control-group">
            <label class="control-label" for="focusedInput">Protein 35 (grams)</label>
            <div class="controls">
              <input class="input-xlarge focused" id="focusedInput" name="mealData[1][6][macro_ratio]" type="text">
              <input type="hidden" name="mealData[1][6][foodCategoryId]" value="6">
            </div>
          </div>
          <div class="control-group">
            <label class="control-label" for="focusedInput">Protein 30 (grams)</label>
            <div class="controls">
              <input class="input-xlarge focused" id="focusedInput" name="mealData[1][7][macro_ratio]" type="text">
              <input type="hidden" name="mealData[1][7][foodCategoryId]" value="7">
            </div>
          </div>
          <div class="control-group">
            <label class="control-label" for="focusedInput">Protein 25 (grams)</label>
            <div class="controls">
              <input class="input-xlarge focused" id="focusedInput" name="mealData[1][8][macro_ratio]" type="text">
              <input type="hidden" name="mealData[1][8][foodCategoryId]" value="8">
            </div>
          </div>
          <div class="control-group">
            <label class="control-label" for="focusedInput">Protein 20 (grams)</label>
            <div class="controls">
              <input class="input-xlarge focused" id="focusedInput" name="mealData[1][9][macro_ratio]" type="text">
              <input type="hidden" name="mealData[1][9][foodCategoryId]" value="9">
            </div>
          </div>
        </fieldset>
        <ul class="pager wizard">
          <li class="previous first" style="display:none;"><a href="javascript:void(0);">First</a></li>
          <li class="previous"><a href="javascript:void(0);">Previous</a></li>
          <li class="next last" style="display:none;"><a href="javascript:void(0);">Last</a></li>
          <li class="next"><a href="javascript:void(0);">Next</a></li>
          <!--<li class="next finish" style="display:none;"><a href="javascript:;">Finish</a></li>-->
          <button type="submit" class="btn btn-primary next finish" style="display:none;">Submit</button>
        </ul>
      </form>
    </div>
    <div class="tab-pane" id="tab2">
      <form action="process/adminProcess.php?page=addClientMealData" method="post" id="mealForm" class="form-horizontal">
        <fieldset>
          <div class="control-group">
            <label class="control-label" for="focusedInput">Protein 60 (grams)</label>
            <div class="controls">
              <input class="input-xlarge focused" id="focusedInput" name="mealData[2][1][macro_ratio]" type="text">
              <input type="hidden" name="mealData[2][1][foodCategoryId]" value="37">
            </div>
          </div>
          <div class="control-group">
            <label class="control-label" for="focusedInput">Protein 55 (grams)</label>
            <div class="controls">
              <input class="input-xlarge focused" id="focusedInput" name="mealData[2][2][macro_ratio]" type="text">
              <input type="hidden" name="mealData[2][2][foodCategoryId]" value="2">
            </div>
          </div>
          <div class="control-group">
            <label class="control-label" for="focusedInput">Protein 50 (grams)</label>
            <div class="controls">
              <input class="input-xlarge focused" id="focusedInput" name="mealData[2][3][macro_ratio]" type="text">
              <input type="hidden" name="mealData[2][3][foodCategoryId]" value="3">
            </div>
          </div>
          <div class="control-group">
            <label class="control-label" for="focusedInput">Protein 45 (grams)</label>
            <div class="controls">
              <input class="input-xlarge focused" id="focusedInput" name="mealData[2][4][macro_ratio]" type="text">
              <input type="hidden" name="mealData[2][4][foodCategoryId]" value="4">
            </div>
          </div>
          <div class="control-group">
            <label class="control-label" for="focusedInput">Protein 40 (grams)</label>
            <div class="controls">
              <input class="input-xlarge focused" id="focusedInput" name="mealData[2][5][macro_ratio]" type="text">
              <input type="hidden" name="mealData[2][5][foodCategoryId]" value="5">
            </div>
          </div>
          <div class="control-group">
            <label class="control-label" for="focusedInput">Protein 35 (grams)</label>
            <div class="controls">
              <input class="input-xlarge focused" id="focusedInput" name="mealData[2][6][macro_ratio]" type="text">
              <input type="hidden" name="mealData[2][6][foodCategoryId]" value="6">
            </div>
          </div>
          <div class="control-group">
            <label class="control-label" for="focusedInput">Protein 30 (grams)</label>
            <div class="controls">
              <input class="input-xlarge focused" id="focusedInput" name="mealData[2][7][macro_ratio]" type="text">
              <input type="hidden" name="mealData[2][7][foodCategoryId]" value="7">
            </div>
          </div>
          <div class="control-group">
            <label class="control-label" for="focusedInput">Protein 25 (grams)</label>
            <div class="controls">
              <input class="input-xlarge focused" id="focusedInput" name="mealData[2][8][macro_ratio]" type="text">
              <input type="hidden" name="mealData[2][8][foodCategoryId]" value="8">
            </div>
          </div>
          <div class="control-group">
            <label class="control-label" for="focusedInput">Protein 20 (grams)</label>
            <div class="controls">
              <input class="input-xlarge focused" id="focusedInput" name="mealData[2][9][macro_ratio]" type="text">
              <input type="hidden" name="mealData[2][9][foodCategoryId]" value="9">
            </div>
          </div>
        </fieldset>
        <ul class="pager wizard">
          <li class="previous first" style="display:none;"><a href="javascript:void(0);">First</a></li>
          <li class="previous"><a href="javascript:void(0);">Previous</a></li>
          <li class="next last" style="display:none;"><a href="javascript:void(0);">Last</a></li>
          <li class="next"><a href="javascript:void(0);">Next</a></li>
          <!--<li class="next finish" style="display:none;"><a href="javascript:;">Finish</a></li>-->
          <button type="submit" class="btn btn-primary next finish" style="display:none;">Submit</button>
        </ul>
      </form>
    </div>
  </div>
</div>

按照上面的HTML截图:

标签1

Tab 1

标签2

Tab 2

1 个答案:

答案 0 :(得分:1)

您将每个标签用作单独的表单。这就是为什么你只能提交一个标签。仅使用一个在引导选项卡之前打开并在引导选项卡之后关闭的表单

<form action="process/adminProcess.php?page=addClientMealData" method="post" id="mealForm" class="form-horizontal">
    <div class="tab-content">
      .....
    </div>
</form>