JS double-click Variable input box to modify content _javascript skills

Source: Internet
Author: User

Double-click Blank or text into the 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

Double-click Modify 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 '///modify the type of the newly created input element.innerhtml = ';//clear the contents of TD to store the newly created input;
 $ (newobj). attr ({value:oldhtml}); Element.appendchild (newobj)//Put input into TD/BIND mouse to input object newobj.onblur = function () {//To determine whether the conditions for sending Ajax are met if (this.v
   Alue!= oldhtml) {element.innerhtml = This.value;
   var value = This.value;
   alert (value);
   Send AJAX request 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 (' modified successfully ')}else{alert (' Modify failed ');
  }})}else{element.innerhtml = oldhtml;//put the original content//return false;
}
 } Newobj.focus ();
 return false; }

The above is a small set to introduce the JS double-click change Input box to modify the content, I hope to help you, if you have any questions please give me a message, small series will promptly reply to everyone. Here also thank you very much for the cloud Habitat Community website support!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.