Home  >  Article  >  Web Front-end  >  JS double-click the input box to modify the content in batches

JS double-click the input box to modify the content in batches

巴扎黑
巴扎黑Original
2016-12-22 13:58:181096browse

Double-click the blank space or the text becomes an input box to modify the content:

html code

<td class="center" ondblclick="ShowElement(this,&#39;intro&#39;)">{$vo.intro}</td>
<td class="center" ondblclick="ShowElement(this,&#39;address&#39;)">{$vo.address}</td>

js code

//双击修改
function ShowElement(element,abc){
 // console.log(abc);
 var list = abc;
 var me = element;
 var oldhtml = element.innerHTML;
 var newobj = document.createElement(&#39;input&#39;);
 newobj.type = &#39;text&#39;;//修改新创建的input的类型
 element.innerHTML = &#39;&#39;;//清空td中的内容用于存放新创建input;
 $(newobj).attr({ value:oldhtml});
 element.appendChild(newobj);//把input放入td
 //给input对象绑定鼠标移开事件
 newobj.onblur = function(){
  // 判断是否满足发送ajax的条件
  if(this.value != oldhtml){
   element.innerHTML = this.value;
   var value = this.value;
   // alert(value);
   //发送ajax请求
   var id = $(me).parents(&#39;.gradeA&#39;).find(&#39;.sid&#39;).html();
   var url = "{:U(&#39;Admin/Friend/onclick&#39;)}";
   var btn = $(this);
   $.ajax({
      url:url,
      data:{id:id,list:list,value:value},
      type:&#39;post&#39;,
      success:function(data){
         console.log(data);
        if(data == 0){
          alert(&#39;修改成功&#39;)
        }else{
          alert(&#39;修改失败&#39;);
        }
      }
   })
  }else{
   element.innerHTML = oldhtml;//放入原来的内容
   // return false;
  }
 }
 newobj.focus();
 // return false;
 }


Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn