javascript - 检测 TD 可编辑更改并更改 css 颜色
问题描述
这看起来很简单,但我无法找到解决方案。
我有一个 HTML 表格,例如
$('#result_table td').on('change', function() {
console.log("Row Changed!")
})
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<table id="result_table" class="table table-hover">
<thead>
<tr>
<th>Blah</th>
<th>Error</th>
</tr>
</thead>
<tbody>
<tr>
<td>bleh</td>
<td>False</td>
</tr>
<!-- If Error, make it editable but highlight row red-->
<tr bgcolor="#FF9494">
<td contenteditable="true">blah_error</td>
<td contenteditable="true">True</td>
</tr>
</tbody>
</table>
我想要做的是,如果您单击并编辑可编辑内容,将表格行背景颜色更改为不同的颜色。我只是想弄清楚jQuery。
解决方案
在 上使用blur
事件td
,一旦您离开单元格,它将触发您的事件
$('#result_table td').on('blur', function() {
console.log("Row Changed!")
})
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<table id="result_table" class="table table-hover">
<thead>
<tr>
<th>Blah</th>
<th>Error</th>
</tr>
</thead>
<tbody>
<tr>
<td>bleh</td>
<td>False</td>
</tr>
<!-- If Error, make it editable but highlight row red-->
<tr bgcolor="#FF9494">
<td contenteditable="true">blah_error</td>
<td contenteditable="true">True</td>
</tr>
</tbody>
</table>
推荐阅读
- bitcoin - BIP143,原生 P2WPKH,示例 txin 脚本?
- java - 将事件侦听器添加到 MotiveWave UI
- java - java泛型的类型不匹配
- javascript - 嵌套数组树节点 JS
- swift - 使用滑块更改 nslayout 约束大小
- html - CSS flexBox 不会定位到底部
- visual-studio-code - 如何在 VsCode 终端中使用行号获取输出?
- asp.net - 带有图像源的 ERR_SSL_PROTOCOL_ERROR Razor 页面
- jquery - 错误:如何正确关闭我的模式窗口
- javascript - 如何使用 scaleTime 水平定位背景矩形