jquery 中的克隆表行和数学函数 - 如何正确处理?
我不知道从哪里开始?
(文本字段 A / 文本字段 B) = 文本字段 C
并自动重复/克隆此表行。在文本字段 B 的按键上进行更改。基本上意味着在进行第一次计算后,将弹出具有唯一 id 等的另一行
<table>
<tr>
<td><input type="text" id="A" name="A"></td>
<td><input type="text" id="B" name="B"></td>
<td><input type="text" id="C" name="C" value=""></td>
</tr>
</table>
// Clone table rows
$(function() {
var i = 1;
$("#A").clone(function() {
$("table tr:first").clone(true).find("input").each(function() {
$(this).val('').attr('id', function(_, id) { return id + i });
$(this).val('').attr('name', function(_, name) { return name + i });
}).end().appendTo("table");
i++;
$("#C").val(Math.round(($("#A").val() / $("#B").val()) * 100 )+ "%");
});
。});
I don't know where to begin?
(textfield A / textfield B) = textfield C
And repeat/clone this table row automaticly .change on keyup of textfield B. Basically meaning that after the first calculation is made, another row will popup with unique ids etc.
<table>
<tr>
<td><input type="text" id="A" name="A"></td>
<td><input type="text" id="B" name="B"></td>
<td><input type="text" id="C" name="C" value=""></td>
</tr>
</table>
// Clone table rows
$(function() {
var i = 1;
$("#A").clone(function() {
$("table tr:first").clone(true).find("input").each(function() {
$(this).val('').attr('id', function(_, id) { return id + i });
$(this).val('').attr('name', function(_, name) { return name + i });
}).end().appendTo("table");
i++;
$("#C").val(Math.round(($("#A").val() / $("#B").val()) * 100 )+ "%");
});
});
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我很努力地试图理解你的问题。我将你的问题解释为:
演示:http://jsfiddle.net/vpsv9/
HTML:
JavaScript:
I tried hard to understand your question. I have interpreted your question as:
DEMO: http://jsfiddle.net/vpsv9/
HTML:
JavaScript:
Fwiw,我有一个与 Rob 的答案非常接近的解决方案: http://jsfiddle.net/49DGP/2/
Fwiw, I have this solution which is very close to Rob's answer : http://jsfiddle.net/49DGP/2/