Heim  >  Artikel  >  Web-Frontend  >  不用ajax实现点击文字即可编辑的方法_javascript技巧

不用ajax实现点击文字即可编辑的方法_javascript技巧

WBOY
WBOYOriginal
2016-05-16 19:07:151086Durchsuche

刚接触creatElement ,appendChild 等东东!呵呵!
写了这个东西,可能在高手看来,非常的稚嫩!不过完全自己写的!
还没有完善,请大侠指导!!
看代码

复制代码 代码如下:

nbsp;HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">

 
   New Document 
  
  <script> <BR> <!-- <BR> function isIE(){ //ie? <BR> if (window.navigator.userAgent.indexOf("MSIE")>=1) return true; <BR> else return false; <BR>} <BR>if(!isIE()){ //firefox innerText define <BR> HTMLElement.prototype.__defineGetter__("innerText", <BR> function(){ <BR> return this.textContent; <BR> } <BR> ); <BR> HTMLElement.prototype.__defineSetter__("innerText", <BR> function(sText){ <BR> this.textContent=sText; <BR> } <BR> ); <BR>}function $(e){ <BR> return document.getElementById(e); <BR> } <BR> var arr=new Array(); <BR> function check(e){ <BR> var v=0; <BR> for(i=0;i<arr.length;i++) <BR> {if(arr[i]==e) v=1; <BR> else v=0;} <BR> if(v) return true; <BR> else return false; <BR> } <BR> function edit(e){ <BR> var x=$(e); <BR> var str=x.innerText; <BR> if (check(e)) <BR> { <BR> //alert("已经存在在数组里!"); <BR> //alert(str); <BR> var b=$(e+"fa"); <BR> str=$(e+"faz").value; <BR> b.removeChild($(e+"faz")); <BR> x.innerText=str; <BR> }else{ <BR> //alert("没有存在在数组里!"); <BR> a1=document.createElement("div"); <BR> a1.id=e+"fa"; <BR> a=document.createElement("INPUT"); <BR> a.name=e; <BR> a.id=e+"faz"; <BR> a.value=str; <BR> x.innerHTML=""; <BR> x.appendChild(a1); <BR> a1.appendChild(a); <BR> if(arr.length==0) arr[0]=e; <BR> else arr[arr.length]=e; <BR> //alert(a.name); <BR> } <BR> } <BR> --> <BR> </script>
 
 
 
可编辑的内容

 
可编辑的内容

 


最后解决浏览器问题的代码

[Ctrl+A 全选 注:如需引入外部Js需刷新才能执行]
Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn