JS双击变input框批量修改内容
双击空白或者文字变成input框修改内容:
html代码
<td class="center" ondblclick="ShowElement(this,'intro')">{$vo.intro}</td> <td class="center" ondblclick="ShowElement(this,'address')">{$vo.address}</td>
js代码
//双击修改 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; }
相关推荐
huha 2020-10-16
TLROJE 2020-10-26
echoes 2020-08-20
nercon 2020-08-01
zhanghaibing00 2020-06-28
Aveiox 2020-06-25
henryzhihua 2020-06-21
zhoutaifeng 2020-06-17
liangzhouqu 2020-06-16
TONIYH 2020-06-11
开心就好 2020-06-10
x青年欢乐多 2020-06-06
KyrieHe 2020-06-03
bertzhang 2020-06-02
haokele 2020-05-29
niehanmin 2020-05-28
davidliu00 2020-05-26