我有一个关于 javascript 和 jQuery 的问题。我对此很陌生。 我使用 jQuery 表排序。我想知道如何更改一个单元格的值。
也许我必须使用这样的东西:
$(function() {
$("table").tablesorter({ sortList: [[3,1],[0,0]] });
$("table tbody td.discount").click(function() {
// randomize a number
var resort = "", // resort variable set to anything BUT false (without quotes) will trigger the automatic resort
discount = '$' + Math.round(Math.random() * Math.random() * 100) + '.' + ('0' + Math.round(Math.random() * Math.random() * 100)).slice(-2);
$(this).text(discount);
// set resort flag to false to prevent automatic resort
// leave the resort flag as undefined, or with any other value, to automatically resort the table
$("table").trigger("updateCell",[this, resort]);
return false;
});
});
在此示例中,我可以在单击单元格时更改单元格的值。 我想将单元格值更改为我的 JavaScript 函数。 我怎样才能做到这一点?
最佳答案
HTML
<table id="myTbl">
<tr>
<td>Joe</td>
<td>White</td>
<td>25</td>
</tr>
<tr>
<td>Joe1</td>
<td>White1</td>
<td>2522</td>
</tr>
</table>
JS
$(function () {
$("#myTbl").delegate("td", "click", function () {
var $this = $(this);
console.log($this);
$this.html("New Value");
});
});
关于javascript - 更改 jQuery 单元格表值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23013232/