Common Methods for div editing using javascript

Source: Internet
Author: User

Function: enables instant editing of webpage content to increase the availability and interactivity of pages.
Method 1: Use the textarea label directly. Run the following code:
<! Doctype html public "-// W3C // dtd html 4.0 Transitional // EN"> <HTML> <HEAD> <TITLE> New Document </TITLE> <meta name = "Generator "CONTENT =" EditPlus "> <meta name =" Author "CONTENT =" "> <meta name =" Keywords "CONTENT =" "> <meta name =" Description "CONTENT = ""> <style type = "text/css"> # info {font-size: 12px; overflow: hidden; background-color: # ffffcc; color: black; padding-right: 5px; padding-left: 5px; font-family: courier; width: 100%; letter-spacing: 0; line-height: 12px; border-style: none ;} </style> </HEAD> <BODY> <pre class = "code" id = "info" onblur = "saveInfo ()" onmouseout = "saveInfo () "onkeyup =" setRows () "> </textarea> </BODY> </HTML>
[Ctrl + A select all Note: If you need to introduce external Js, You need to refresh it to execute]
Idea: Design textarea in CSS style to make the user feel like textarea, and save user data through ajax using attributes such as onblur and oumouseout.
Method 2: Add input to the page using document. createElement. Run the following code:
<! Doctype html public "-// W3C // dtd html 4.0 Transitional // EN"> <HTML> <HEAD> <TITLE> New Document </TITLE> <meta name = "Generator "CONTENT =" EditPlus "> <meta name =" Author "CONTENT =" "> <meta name =" Keywords "CONTENT =" "> <meta name =" Description "CONTENT = ""> </HEAD> <BODY> click here to edit </BODY> </HTML>
[Ctrl + A select all Note: If you need to introduce external Js, You need to refresh it to execute]
Ideas:
1. When the user clicks the mouse over an editable area, the background color and other methods are used to remind the user to edit the area.
2. When the user clicks this area, that is, the onclick event, the original content is cleared first, and an input box and an input button are created temporarily.
3. After modification, click "save" to write new data to the database through ajax.

PS: the code of the second method has some problems. If you have time, try again.

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.