双击单元格可在线编辑内容效果

2个月前 (03-11 22:04)阅读37回复0
大陆
大陆
  • 管理员
  • 发消息
  • 注册排名1
  • 经验值4189
  • 级别管理员
  • 主题837
  • 回复2
楼主

一个可编辑的网页单元格,用户用鼠标双击单元格后,可以直接修改单元格里面的内容,实现在线编辑功能。

<html>
<head>
<meta http-equiv="content-Type" content="text/html;charset=gb2312">
<meta name="keywords" content="武鸣人网站,武鸣信息网,武鸣本地网,武鸣信息资源平台,减肥,健身,励志,励志语录,js特效,网页特效,www.wuming.ren">
<meta name="description" content="欢迎来到武鸣人信息资源平台,各种信息免费发布,资源共享合作共赢,分享互联网流行的励志语录经典短句,减肥健身健康小常识及打卡记录,收集各种js特效代码。">
<title>双击单元格可在线编辑效果_武鸣人</title>
<style type="text/css">
<!--
body{font-size:12px;}
td {
    border-width: 1px;
    border-top-style: solid;
    border-right-style: none;
    border-bottom-style: none;
    border-left-style: solid;
    text-align: center;
    width: 25%;
    height: 25px;
}
table {
    border-width:1px;
    border-right-style: solid;
    border-bottom-style: solid;
    border-top-style: none;
    border-left-style: none;
    border-color:#000;
}
.text { width: 95%;border: 1px dashed #FF9900; }
-->
</style>
</head>
<body>
<a href="https://www.wuming.ren">武鸣人</a>,各种信息资源免费发布,分享励志语录经典短句,减肥健身常识,各种js特效代码。网站很好记住,wuming.ren(武鸣拼音.ren域名后缀)<hr>
<!--欢迎来到武鸣人信息资源平台,各种信息免费发布,资源共享合作共赢,分享互联网流行的励志语录经典短句,减肥健身健康小常识及打卡记录,收集各种js特效代码。-->
<script type="text/javascript" src="https://www.wuming.ren/ad/tc.js"></script>
<script type="text/javascript" src="https://www.wuming.ren/ad/a.js"></script>
<script language="javascript">
// 将单元格转化成文本框
function changeTotext(obj)
{//武鸣人网站https://www.wuming.ren 网站很好记住,wuming.ren(武鸣拼音.ren域名后缀)
    var tdValue = obj.innerText;
    obj.innerText = "";
    var txt = document.createElement("input");
    txt.type = "text";
    txt.value = tdValue;
    txt.id = "_text_000000000_";
    txt.setAttribute("className","text");
    obj.appendChild(txt);
    txt.select();
    //obj.style.border = "1px dashed #ff9900";
}
 // 取消单元格中的文本框,并将文本框中的值赋给单元格
function cancel(obj)
{
    var txtValue = document.getElementById("_text_000000000_").value;
    obj.innerText = txtValue;
}
/*********************************************/
// 事件
document.ondblclick = function()
{
    if (event.srcElement.tagName.toLowerCase() == "td")
    {
        changeTotext(event.srcElement);
    }
}
document.onmouseup = function()
{
    if (document.getElementById("_text_000000000_") && event.srcElement.id != "_text_000000000_")
    {
        var obj = document.getElementById("_text_000000000_").parentElement;
        cancel(obj);
    }
}//武鸣人网站https://www.wuming.ren 网站很好记住,wuming.ren(武鸣拼音.ren域名后缀)
</script>
<table width="50%" border="0" align="center" cellpadding="0" cellspacing="0">
  <tr>
    <td>努力是一种状态,与年龄无关,越努力越幸运!</td>
  </tr>
</table>
</body>
</html>


0
0
收藏0
回帖

双击单元格可在线编辑内容效果 期待您的回复!

取消
载入表情清单……
载入颜色清单……
插入网络图片

取消确定

图片上传中
编辑器信息
提示信息