Double-click the blank space or the text becomes an input box to modify the content:
html code
<td class="center" ondblclick="ShowElement(this,'intro')">{$vo.intro}</td> <td class="center" ondblclick="ShowElement(this,'address')">{$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('input'); newobj.type = 'text';//修改新创建的input的类型 element.innerHTML = '';//清空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('.gradeA').find('.sid').html(); var url = "{:U('Admin/Friend/onclick')}"; var btn = $(this); $.ajax({ url:url, data:{id:id,list:list,value:value}, type:'post', success:function(data){ console.log(data); if(data == 0){ alert('修改成功') }else{ alert('修改失败'); } } }) }else{ element.innerHTML = oldhtml;//放入原来的内容 // return false; } } newobj.focus(); // return false; }