怎样让你的表格可编辑???

本文提供了一个HTML页面示例,展示了如何通过JavaScript实现表格中单元格内容的在线编辑功能。此功能允许用户直接点击单元格进行修改。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

<HTML>
<HEAD>
<STYLE>
.td1 { color: white; background-color: orange;}
.td2 { color: white; background-color: #0099ff;}
.td3 { color: white; background-color: #336699;}
</STYLE>
<SCRIPT>
function editCell (cell) {
if (document.all) {
cell.innerHTML = '<INPUT ID="editCell"
ONCLICK="event.cancelBubble = true;"
ONCHANGE="setCell(this.parentElement, this.value)"
ONBLUR="setCell(this.parentElement, this.value)"
VALUE="' + cell.innerText + '"
SIZE="' + cell.innerText.length + '">';
document.all.editCell.focus();
document.all.editCell.select();
}
else if (document.getElementById) {
cell.normalize();
var input = document.createElement('INPUT');
input.setAttribute('value', cell.firstChild.nodeValue);
input.setAttribute('size', cell.firstChild.nodeValue.length);
input.onchange = function (evt) {
setCell(this.parentNode, this.value); };
input.onclick = function (evt) {
evt.cancelBubble = true;
if (evt.stopPropagation)
evt.stopPropagation();
};
cell.replaceChild(input, cell.firstChild);
input.focus();
input.select();
}
}
function setCell (cell, value) {
if (document.all)
cell.innerText = value;
else if (document.getElementById)
cell.replaceChild(document.createTextNode(value), cell.firstChild);
}
</SCRIPT>
</HEAD>
<BODY>
<TABLE BORDER="2">
<TR>
<TD ONCLICK="editCell(this);" CLASS="td1">欢迎光临</TD>
<TD ONCLICK="editCell(this);" CLASS="td2">[孟宪会之精彩世界]</TD>
<TD ONCLICK="editCell(this);" CLASS="td3">http://lucky.myrice.com</TD>
</TR>
</TABLE>
</BODY>
</HTML>
**************************************
这个网址也不错---->http://hi.baidu.com/senty/blog/item/0b0a8226797112128b82a152.html/cmtid/52ef510f7504b3206159f3cf
**************************************

本文来自优快云博客,转载请标明出处:http://blog.youkuaiyun.com/net_lover/archive/2001/06/27/6869.aspx
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值