目前我正在使用下面的代码在文本框中输入用户进入的值。jquery - - 我如何简化代码
var test = new Object();
test.attribute = $("#Attribute_0").val();
test.operand = $("#Operand_0").val();
test.value = $("#Value_0").val();
var test = new Object();
test.attribute = $("#Attribute_1").val();
test.operand = $("#Operand_1").val();
test.value = $("#Value_1").val();
但是随着列表的增长我认为会有一些其他更好的方式来做到这一点,所以我来到了这里。
我的HTML代码就会像下面
<div>
<input id="Attribute_0" name="Attribute_1" type="text">
<select id="Operand_0">
<input id="Value_0" type="text">
</div>
<div>
<input id="Attribute_1" name="Attribute_1" type="text">
<select id="Operand_1">
<input id="Value_1" type="text">
</div>
我可以用一些的foreach或任何其他更好的方式简化了我的代码?
请建议
更新
雅我的代码是重复的。
假设如果我有这样的10个列表属性,那么没有必要为每个DIV手动取值。
我该如何轻松地做到这一点W/O重写代码?
你的代码覆盖自己,你到底想要做什么? – smerny 2013-04-11 13:20:47
你知道'class =“”'属性是什么,对吧? – Bojangles 2013-04-11 13:20:47
也许更适合http://codereview.stackexchange.com。 – 2013-04-11 13:21:08