欢迎来到DIVCSS5查找CSS资料与学习DIV CSS布局技术!

DIV+CSS的可编辑表单之鼠标双击文字进行编辑文本的表单特效,提供图例与在线演示,同时打包下载。双击文本后变成输入框可编辑模式,并可提交修改。

可进入编辑模式的特效截图
双击文字可编辑文字表单input特效截图

完整HTML源代码

  1. <!DOCTYPE HTML> 
  2. <HTML xmlns="HTML://www.w3.org/1999/xHTML"> 
  3. <head> 
  4. <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> 
  5. <title>双击文字进行文本编辑 在线演示 www.divcss5.com</title> 
  6. <style> 
  7. input.t {border:1px solid #fff;background:#fff; font-size:14px;
     padding-left:5px; height:30px; line-height:30px; width:300px} 
  8. input.s {border:1px solid #369;background:#fff; padding-left:5px;
     height:30px; line-height:30px; width:300px} 
  9. </style> 
  10. </head> 
  11. <body> 
  12. <input class="t" id="test" readonly value="这里是标题,双击文字后实现编辑文本功能" />
    <input type="submit" value="修改" style="display:none;" id="submit" /> 
  13. <script type="text/javascript"> 
  14. var test = document.getElementById("test"); 
  15. var mysubmit = document.getElementById("submit"); 
  16. test.ondblclick = function() 
  17.  this.readOnly = false
  18.  this.className = "s"
  19.  mysubmit.style.display = ""
  20. mysubmit.onclick = function() 
  21.  test.readOnly = true
  22.  test.className = "t"
  23.  this.style.display = "none"
  24. </script> 
  25. </body> 
  26. </HTML> 

复制以上完整HTML+JS代码即可使用。

在线演示:查看案例

打包下载:

如需转载,请注明文章出处和来源网址:http://www.divcss5.com/css-texiao/texiao575.shtml