我正在使用带有以下标记的 MVC3 剃须刀:
<div class="budget">
<!--line item-->
<div class="budget-row">
<div class="row">
<div class="twelve columns">
<div class="row">
<div class="two mobile-one columns">
<label class="right inline">Item:</label>
</div>
<div class="ten mobile-three columns">
@Html.TextBox("description[]", "", new { @class = "expand" })
</div>
</div>
<div class="row">
<div class="two mobile-one columns">
<label class="right inline">Cost:</label>
</div>
<div class="two mobile-one columns field-left">
@Html.TextBox("amount[]", "0", new { @class = "expand" })
</div>
<div class="one mobile-one columns">
<label class="right inline">Markup:</label>
</div>
<div class="one mobile-one columns field-left">
@Html.TextBox("markup_amount[]", "0", new { @class = "expand" })
</div>
<div class="one mobile-one columns field-left">
<select id="markup_type[]" style="display:none;">
<option value="P" SELECTED>%</option>
<option value="D">$</option>
</select>
</div>
</div>
</div>
</div><!--row-->
</div>
<!--end line item-->
<a class="button radius small success middle" href="#" id="submit">Submit</a>
</div>
“budget” div 是整体 div,“budget-row” div 可以是一行或多行。我正在寻找一个迭代捕获每个输入的值。我试过这个:
$("#submit").click(function() {
$(".budget input[type=text]").each(function() {
alert(this.value);
});
return false;
});
坦率地说,尝试了很多事情,在这一点上可能还没有接近。这也只会返回我的文本框。
谢谢
编辑这是添加输出代码:
<div class="budget">
<!--line item-->
<div class="budget-row">
<div class="row">
<div class="twelve columns">
<div class="row">
<div class="two mobile-one columns">
<label class="right inline">Item:</label>
</div>
<div class="ten mobile-three columns">
<input class="expand" id="description__" name="description[]" type="text" value="" />
</div>
</div>
<div class="row">
<div class="two mobile-one columns">
<label class="right inline">Cost:</label>
</div>
<div class="two mobile-one columns field-left">
<input class="expand" id="amount__" name="amount[]" type="text" value="0" />
</div>
<div class="one mobile-one columns">
<label class="right inline">Markup:</label>
</div>
<div class="one mobile-one columns field-left">
<input class="expand" id="markup_amount__" name="markup_amount[]" type="text" value="0" />
</div>
<div class="one mobile-one columns field-left">
<select id="markup_type[]" style="display:none;">
<option value="P" SELECTED>%</option>
<option value="D">$</option>
</select>
</div>
</div>
</div>
</div><!--row-->
</div>
<!--end line item-->
<a class="button radius small success middle" href="#" id="submit">Submit</a>
</div>