一、js部分
javascript
<script type="text/javascript"> <!-- var _edit = { IN: function (obj, act, id) { var tag = obj.firstChild.tagName; if (typeof(tag) != "undefined" && (tag == "INPUT" || tag == "TEXTAREA"))return; var org = obj.innerHTML; var orglen = org.replace(/[^\x00-\xff]/g,'**').length; if (obj.offsetHeight <= 22) { var val = window.ActiveXObject ? obj.innerText : obj.textContent; var txt = document.createElement("INPUT"); txt.value = val; txt.style.background = "#FFC"; txt.style.width = obj.offsetWidth + "px" ; obj.innerHTML = ""; obj.appendChild(txt); txt.focus(); txt.onblur = function(e){ obj.innerHTML = txt.value; _edit.QUERY(act,txt.value); return false; } return false; }else{ var content = obj.innerHTML; var html = document.createElement('TEXTAREA'); html.style.width = obj.offsetWidth + "px"; html.style.height = obj.offsetHeight + "px"; obj.innerHTML = ""; html.value = content; obj.appendChild(html); html.focus(); html.onblur = function(e){ obj.innerHTML = html.value; _edit.QUERY(act,obj.innerHTML); } return false; } } } var editContent = _edit.IN; // --> </script>
二、html部分html
<td class="hidden-480" id="content" onclick="_edit.IN(this,'index.html?act=edit',3)"> 這是可編輯的耳標 </td>
就這樣能夠實現點擊編輯並保存功能。
java