【发布时间】:2012-04-02 04:34:02
【问题描述】:
我想在javascript中获取数组的输入文本值
这是我的代码:
Item : <input id="t_item" name="t_item[]" type="text" class="teks3">
Cost : <input id="t_cost" name="t_cost[]" type="text" class="teks3">
<input type="button" id="tb_more_item" class="add_file"/>
js代码是:
$("input#tb_more_item").click(function(){
var new_file = $("
Item : <input id='t_item' name='t_item[]' type='text' class='teks3'/>
Cost : <input id='t_cost' name='t_cost[]' type='text' class='teks3'/>
");
$("div#div_item").append(new_file).fadeIn();
});
我尝试使用此代码获得更多项目价值:
var item_value = [], cost_value = [];
$("input#t_item").each(function() {
$thisItem = $(this);
item_value = $thisItem.val();
});
$("input#t_cost").each(function() {
$thisCost = $(this);
cost_value = $thisCost.val();
});
alert(item_value +"-"+ cost_value );
结果是获取我在输入文本中输入的最后一个值。
有人有解决办法吗?
谢谢
【问题讨论】:
-
但是没有发现错误..你能解决吗?如何获取输入的文本数组值?
标签: javascript arrays input