JQuery改变表格单元格的内容 [英] JQuery changing content of table cell

查看:122
本文介绍了JQuery改变表格单元格的内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好的,这是一个令人尴尬的简单问题。为什么下面的jQuery示例不起作用?显然它应该将表中的'a'更改为'hello'。

OK, this is an embarrassingly simple question. Why doesn't the following jQuery example work? Obviously it is supposed to change the 'a' in the table to 'hello'.

HTML code:

HTML code:

    <table id='table1'>
      <tr>
          <td>a</td>
          <td>b</td>
      </tr>
    </table>​

JavaScript(JQuery)代码:

JavaScript (JQuery) code:

    $("#table1 td:contains('a')").innerHTML="hello";


推荐答案

使用像这样的html函数

use the html function like this

 $("#table1 td:contains('a')").html("hallo");

如果你想使用innerHTML(是一种DOM方法,而不是Jquery方法),你必须选择首先是DOMElement。

if you want use innerHTML (is a DOM method, not a Jquery Method), you have to select the DOMElement first.

jQuery(document).ready(function(){
    $("#table1 td:contains('a')").each(function(){
    jQuery(this)[0].innerHTML = "Hallo";
    });
});

这篇关于JQuery改变表格单元格的内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆