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.