简单的一个效果,JQUERY大大简化了代码..... 不得不说JQ之强大
XML/HTML代码
- <html>
- <head>
- <meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
- <script type="text/javascript" src="jquery.js"></script>
- <script type="text/javascript">
- function changeClick() {
- var obj = document.getElementById('c7is');
- var newobj = document.createElement('input');
- var text;
- typeof (text=obj.innerText)=='undefined' ? obj.textContent : obj.innerText;
- newobj.setAttribute('id','c7is');
- newobj.setAttribute('type','text');
- newobj.setAttribute('value',text);
-
- newobj.onblur=function() {
- if(typeof obj.innerText=='undefined'){
- obj.textContent = newobj.value;
- }else {
- obj.innerText = newobj.value;
- }
- document.body.replaceChild(obj,newobj);
- }//失去焦点
- document.body.replaceChild(newobj,obj);
-
- }
- function xx() {
- $('#c7').replaceWith('<div id="c7" onClick="JchangeClick()">'+$('#c7').val()+'</div>');
- }
- function JchangeClick() {
- $('#c7').replaceWith('<input type="text" id="c7" value="'+$('#c7').text()+'" onblur="xx()"/>');
- }
- </script>
- </head>
- <body>
- <div id="c7is" ondblClick="changeClick()">c7isqingyaohua</div>
- <div id="c7" ondblClick="JchangeClick()">C7_yaohuaq</div>
- </body>
- </html>