在javascript中编辑表格

时间:2015-09-16 15:09:22

标签: javascript jquery html

我想在按钮事件上删除/更新表。

我有一张这样的表

  <table class="SimpleCalendar">
<thead>
    <tr>
        <th>Mon</th>
        <th>Tue</th>
        <th>Wed</th>
        <th>Thu</th>
        <th>Fri</th>
        <th>Sat</th>
        <th>Sun</th>
    </tr>
</thead>
<tbody>
    <tr>
        <td> </td>
        <td> </td>
    </tr>
    <tr>
        <td> </td>
        <td> </td>
    </tr>
    <tr>
        <td> </td>
        <td> </td>
    </tr>
</tbody>
</table>

我想通过点击按钮来修改内部HTML

$('.submit').click(function() 
{   
    var mytable = $('.SimpleCalendar');
    mytable.innerHTML = "test";
});

当我使用firebug或浏览器的分析按钮时,我可以看到innerHTML已更改,但它在我的网页上反复显示相同的表格。

enter image description here

1 个答案:

答案 0 :(得分:2)

$('.SimpleCalendar')返回一个jQuery集合。 innerHTMLHTMLElement个对象的属性。在jQuery集合上定义innerHTML属性实际上没有做任何事情。您应该使用.get()方法从集合中获取jQuery包装元素,然后重置innerHTML属性或使用jQuery .html()方法。

相关问题