更改jQuery单元格表值

Change jQuery cell table values

本文关键字:单元格 jQuery 更改      更新时间:2023-09-26

我有一个关于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");
    });
});