我正在尋找在我的表中做一些計算。表格內容來自ajax。但是對於下面的內容,計算僅完成一行(第一行)。當我試圖添加。每個函數都沒有發生。乘以兩列,結果在另一列
Ajax代碼
$.ajax({
type: "Post",
url: '@Url.Action("function", "Controller")',
data: '{selectedValues: "' + selectedValues + '"}',
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (data, textStatus, jqXHR) {
var row = "";
$.each(data, function (index, item) {
row += "<tr class='odd'><td><input type='checkbox'></td><td class='product-title'>" + item.Name + "</td><td>" + item.MaxIssueLimit + "</td><td class='num-pallets'><input type='text' class='num-pallets-input' id='sparkle-num-pallets' max=" + item.MaxIssueLimit + " oninput='calculate()'></input></td><td class='times'>X</td><td class='price-per-pallet'><input type='text' class='num-pallets-input' id='cost' oninput='calculate()' value=" + item.UnitPrice + " disabled='disabled'></td><td class='equals'>=</td><td class='row-total'><input type='text' class='row-total-input' id='sparkle-row-total' disabled='disabled'></input></td></tr>";
});
$("#contacts").html(row);
},
});
的Javascript
function calculate() {
var my1 = document.getElementById('sparkle-num-pallets').value;
var my2 = document.getElementById('cost').value;
var result = document.getElementById('sparkle-row-total');
var myResult = my1 * my2;
result.value = myResult;
}
任何幫助表示讚賞。在此先感謝
[請不要把問題標題標籤(https://stackoverflow.com/help/tagging) – Liam