在上边双击文章题目可以编辑标题,以实现更换标题功能。
代码:
效果: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=gb2312" /> <meta name="author" content="wuleying" /> <title>无标题文档</title> <style> input.a {border:1px solid #fff;background:#fff;} input.b {border:1px solid #369;background:#fff;} </style> </head> <body> <input class="a" id="test" readonly value="这里是标题" type="text" /><input type="submit" value="修改" style="display:none;" id="submit" /> <script type="text/javascript"> var test = document.getElementById("test"); var mysubmit = document.getElementById("submit"); test.ondblclick = function() { this.readOnly = false; this.className = "b"; mysubmit.style.display = ""; } mysubmit.onclick = function() { test.readOnly = true; test.className = "a"; this.style.display = "none"; } </script> </body> </html>