0
我想在另一個表單中添加一堆相同的表單。我想我很接近,但我不知道斷開連接的位置。我試圖將表格總計起來,然後總計表格中的總數到最後。在一個表格中總計一個類的總數
HTML
<div class="container">
<div class="row-fluid">
<div class "span12 exercise1 addWorkout">
<img src="assets/img/plus01.jpg" class="addWorkout imgButton">Add A Workout</div>
<!-- <img src="assets/img/minus01.png" class="delWorkout imgButton"> -->
<div class="span12 workoutList" id="workoutList">
<div class="cloneMe">
<div class="row-fluid exercise1 one_rep_calc_container workoutOrgin span4">
<div class="oneWorkout">
<form>
<div class="span4">Weight
<input class="weight" type="number" name="weight" size="2">
</div>
<div class="span4">Reps
<input class="reps" type="number" name="reps" size="2">
</div>
<div class="span4">OneRepMax
<input class="one_rep_max" type="number" Name="oneRepMax" size="2">
</div>
<div class="span4">TotalWeight
<input class="totalWeight" type="number" Name="totalWeight" size="2">
</div>
</form>
<!-- <img src="assets/img/plus01.jpg" class="addWorkout exercise1 imgButton">
-->
<img src="assets/img/minus01.png" class="delWorkout imgButton">
</div>
</div>
</div>
</div>
<div class="span12 workoutResults">
<form>
<div class="span4">Total
<input class="totalAll" id="subtotal" type="number" name="total" size="2">
</div>
</form>
</div>
</div>
</div>
jQuery的
$('.totalWeight').change(function() {
var parent = $(this).parents('.workoutResults .one_rep_calc_container');
var totalWeight = parseInt(parent.find('.totalWeight').val(), 10);
var totalAll = parseInt(parent.find('.totalAll').val(), 10);
if (weight > 0) {
var totalWeightval = 0;
$('.totalWeight').each(function() {
totalWeightval += parseFloat(this.value);
});
parent.find('.totalAll').val(totalWeightval);
} else {
parent.find('.totalAll');
}
});
我如何能更好地組織我的代碼,這將是偉大的,以及任何建議。
究竟是什麼問題?輸入是否更新?我的建議,仔細檢查你的父母選擇器,因爲它不符合你的標記,並嘗試改進你的功能的邏輯。 –