1
下面是我的工作: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);
});
A [jsFiddle](http://jsfiddle.net/)會有所幫助。 – sczizzo 2011-12-30 02:32:52
當然,謝謝! http://jsfiddle.net/CzZxf/ – user1040259 2011-12-30 02:47:37