这是我的工作: 3 个使用数学函数 A / B = C 克隆的文本字段。完美运行。
问题:我想设置 A、B 和 C 的“on keyup”文本字段值,以便该值实际读取输入到文本字段中的内容。(参见代码注释中的“不正确”)
$("#math-table input").live("keyup", function(){
var id = this.id.match(/\d+/);
$("#C"+id).val( Math.round (($("#A"+id).val() / $("#B"+id).val()) * 100) + "%" );
$('#A1'+id).attr('value', ($('#A1'+id).val())); // NOT RIGHT?
$('#B1'+id).attr('value', ($('#B1'+id).val())); // NOT RIGHT?
$('#C1'+id).attr('value', ($('#C1'+id).val())); // NOT RIGHT?
});
var uniqueIds = $("#math-table tr").length;
$("#math-table input[id^='B']").live("change", function(){
var $thisRow = $(this).closest("tr"),
$clone = $thisRow.clone(), // Clone row
$inputs = $clone.find("input").val("");// Reset values, return all inputs
uniqueIds++; //Increment ID
$inputs[0].id = "A" + uniqueIds;
$inputs[1].id = "B" + uniqueIds;
$inputs[2].id = "C" + uniqueIds;
$thisRow.after($clone);
});