表td的onchange事件? [英] onchange event of table td?
本文介绍了表td的onchange事件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
//表生成代码
< table id = custorder2> < HEAD> < TR> < td>更改它< / td> < / TR> < /头> < TBODY> < TR> < TD→1< / TD> < / TR> < / tbody的> < /表>
//用于触发类似事件
< $ p $
$(document).ready(function(){
$('#custorder2 tr td')。change(function(){
console.log call);
})
})
更改单元格如果你正在考虑标准编辑单元格,那么我想建议一个替代方案,例如,
< script language =javascript>
函数dotest(元素,事件)
{
//将内容作为文本获取,您可以根据需要使用innerHTML
alert(content+ element.textContent)
}
< / script>
< table cellpadding =2cellspacing =0border =1width =100%>
< tr>
< td contenteditable =trueonkeyup =javascript:dotest(this,event);>
测试
< / td>
< / tr>
< / table>
取决于html5属性和按键(可以直接编辑单元格的场景)
希望你觉得它有用
I want to trigger an event onchange of data of a table cell.
// table generating code
<table id=custorder2 > <head> <tr> <td>change it</td> </tr> </head> <tbody> <tr> <td>1</td> </tr> </tbody> </table>
// for triggering event something like this
$(document).ready(function(){
$('#custorder2 tr td').change(function() {
console.log("call");
})
})
on change of cell value this call should be printed.
解决方案
If you are considering standard edit to cell, then i would like to suggest an alternative,
<script language="javascript">
function dotest(element,event)
{
//GET THE CONTENT as TEXT ONLY, you may use innerHTML as required
alert("content " + element.textContent)
}
</script>
<table cellpadding="2" cellspacing="0" border="1" width="100%">
<tr>
<td contenteditable="true" onkeyup="javascript:dotest(this,event);">
Testing
</td>
</tr>
</table>
Relies on html5 attribute and keypress (In scenarios where cells can be directly edited)
Hope you find it useful
这篇关于表td的onchange事件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文