Click jquery to edit the plug-in.

Source: Internet
Author: User

I recently used jquery to write something and found that it is still very useful. This is a tutorial on jquery, and I wrote one after simulation.

Read the code.

 

Jquery. noconflict ();
Function sanshi_edit (ID, editclass, postpage, isnotnull)
...{
VaR savebutton = "savebutton ";
VaR cancelbutton = "cancelbutton ";
// Var isnotnull = true;
VaR idstr = '#' + ID;
// Click the event
Jquery (idstr). Click (function ()...{
VaR textarea = '<div> <textarea rows = "3" Cols = "40"> '{jquery(idstr;.html () +' </textarea> ';
VaR button = '<div> <input type = "button" value = "save" class = "' + savebutton + '"/> <input type = "button" value =" cancel "class =" '+ cancelbutton +' "/> </div> ';
VaR revert = jquery(idstr).html ();
Jquery (idstr). After (textarea + button). Remove ();
// Click the Save button to listen to the event
Jquery ('.' + savebutton). Click (function ()...{
// Save the event
VaR postcontent = jquery (this). Parent (). siblings (0). Val ();
If (! Isnotnull & postcontent = "")
...{
Alert ("the content you entered cannot be blank ");
Return false;
} Else ...{
Sanshi_edit_save (true, jquery (this), postcontent, ID, editclass, postpage, isnotnull );
}
});
// Click the event button to cancel the listener.
Jquery ('.' + cancelbutton). Click (function ()...{
// Cancel the event
Sanshi_edit_save (false, jquery (this), revert, ID, editclass, postpage, isnotnull );
});
});
// Listen to mouse events
Jquery (idstr). Mouseover (function ()...{
Jquery (idstr). addclass (editclass );
});
Jquery (idstr). mouseout (function ()...{
Jquery (idstr). removeclass (editclass );
});
// Sanshi_edit (idstr, editclass );
// Save the modified information
Function sanshi_edit_save (issave, OBJ, text, ID, editclass, postpage, isnotnull)
...{
If (issave)
...{
// If the submit page is set, submit
If (postpage)
...{
// Debug 2008-2-1 debugging
// $. Post (postpage, {contents: text}, function (text) {$ ("# debug" ).html (text );});
Jquery. Post (postpage,... {contents: text });
}
Alert ("saved successfully ");
}
OBJ. parent (). parent (). after ('<Div id = "' + ID + '">' + TEXT + '</div> '). remove ();
Sanshi_edit (ID, editclass, postpage, isnotnull );
}
}

 

Easy to use

 

<SCRIPT>...
Jquery ("document"). Ready (function ()...{
New sanshi_edit ("sanshiedit1", "editable", "my_edit.php ");
});
</SCRIPT>
<Div id = "sanshiedit1">
Edit me
</Div>

 

Let's talk about the parameters.

Sanshi_edit ("sanshiedit1", "editable", "my_edit.php ");

The first parameter is the content of the DIV to be edited.

The second parameter is the style for editing the area mouse

The third parameter is submitted to that page.

Note that the submission method is post and the submitted variable is named contents.

Background Receiver

 

$ Text = strip_tags ($ _ post ["contents"]);

 

Jquery-like Google drop-down form plug-in

Http://phpitem.com/search.php view results

Author sanshi0815
Mail sanshi0815@tom.com

Blog: http://blog.csdn.net/sanshi0815

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.