Click Edit JS to make text text box

Source: Internet
Author: User

Imitate the QQ space layout, in order to simulate the friend Group editing section, a lot of collection of JS code, after multiple comparisons and modifications, and finally refined to the more practical script I have encountered so far, which I like the advantages: No ID definition, only define the class can,, code is simple, especially for the background, because, Friends have been successfully used in the background interaction, the first to provide code, make a mark (PS: Forget where to download the JS source, but very grateful to the author of the Great God ...) Thank... )

<script>
$ (function () {
Gets the element that is class CAName
$ (". T2"). Click (function () {
var td = $ (". T1");
var txt = td.text ();
var input = $ ("<input type= ' text ' value= '" + txt + "'/>");
td.html (input);
Input.click (function () {return false;});
Get focus
Input.trigger ("Focus");
The text box loses focus, commits the content, and becomes text again
Input.blur (function () {
var newtxt = $ (this). Val ();
Determine if the text has been modified
if (newtxt! = txt) {
Td.html (Newtxt);
/*
* This section of the database does not need to be used
var caid = $.trim (Td.prev (). text ());
Ajax asynchronously changes the database, plus the parameter date is to solve the cache problem
var url = ".. /common/handler2.ashx?caname= "+ newtxt +" &caid= "+ CAID +" &date= "+ new Date ();
Using the Get () method to open a generic handler, data accepts the returned parameter (the method that returns the parameter in the generic handler context. Response.Write ("Parameters to return");)
Database modification is done in a generic handler
$.get (URL, function (data) {
if (data== "1")
{
Alert ("The category already exists!") ");
td.html (TXT);
Return
}
alert (data);
Td.html (Newtxt);
});
*/
}
Else
{
Td.html (Newtxt);
}
});
});
});

/*
document.getElementById ("Click1"). Onclick=function () {
var Text=document.getelementbyid ("T1");
var val=text.innerhtml;
Text.innerhtml= "<input type= ' text ' id= ' m ' value=" +val+ "/>";
document.getElementById ("M"). AddEventListener ("Blur", function (e) {
Text.innerhtml=document.getelementbyid ("M"). Value;
});
};
*/
</script>

The body part, does not make the CSS definition, the effect can realize:

<span class= "T1" > Default grouping </span>

<a class= "T2" > Edit </a>

<p> Description: Click Edit to modify the default grouped text content </p>

Load a jquery plugin arbitrarily

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.