【发布时间】:2015-09-17 18:20:57
【问题描述】:
我在我的项目中使用 jquery 和数据表。
我现在想要的是在单击按钮时向单元格添加 CSS,即更改单元格颜色。我只想更改单个特定单元格的值而不是整行
我尝试了下面的方法,但没有成功
<table id="food">
<thead>
<tr>
<th>Number</th>
<th>Name</th>
<th>Type</th>
</tr>
</thead>
<tbody>
<tr>
<td>1</td>
<td>Apple</td>
<td>Fruit</td>
</tr>
<tr>
<td>2</td>
<td>Mango</td>
<td>Fruit</td>
</tr>
<tr>
<td>3</td>
<td>Grape</td>
<td>Fruit</td>
</tr>
</tbody>
</table>
<button id='button1'>Click me</button>
这里是jquery
$('#button1').click(function(){
//Here I want to change row 1,col 3 to red color
var cell = table.row(1).column(3).node();
$(cell).addClass('change-color');
});
谢谢
【问题讨论】:
-
你想改变整行的css吗?这个复选框在哪里?每行的第一列?请在问题中详细描述您的情况
-
嗨,dhiraj,删除了所有不必要的东西..现在问题看起来简单明了..
-
能否提供表格的HTML?
标签: jquery datatables