javascript - 更改 jQuery 单元格表值

标签 javascript jquery html

我有一个关于 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/

相关文章:

javascript - DataTable 1.10 - 禁用某些列的行选择事件

javascript - 如何使用 JavaScript 获取 HTML Table 中 td 内的链接文本?

jquery - 如何使用 jquery 平衡两个动态表行的高度

javascript - 向上滚动后固定 div 并在页面刷新后保持固定

Javascript:如何将输入打印到按类选择的 <div> ?

javascript - 如何在 jQuery 中创建滚动菜单?

java - 从 Servlet 获取复选框值

javascript - 为什么空结果会卡住脚本以及如何避免它?

javascript - 验证 javascript/jquery 中的 url 格式

javascript - 闭包在对象之间共享变量