Automatic saving is often used in the editor, in order to achieve data timing save we will use the AJAX function, let's look at an input box below to lose focus automatically save the input box data instance
Recently do an input box loses focus when automatically save the data function, of course, jquery selector Select Input,blur, Ajax to submit data to PHP file, php file to save the data. The main thing is to pay attention to the problem of Chinese, so the middle need to turn the code.
The following instance is a list page, which is a bit like Excel.
HTML code:
The code is as follows |
Copy Code |
{$id} |
|
{$description} |
Preview edits |
|
JS Code:
The code is as follows |
Copy Code |
|
PHP Code: (Functions, methods that refer to Dedecms)
The code is as follows |
Copy Code |
if ($dopost = = ' Ajaxsave ') { $value = UrlDecode (Autocharset ($value, "Utf-8″," Gb2312″)); Update Main Table $inQuery = "UPDATE ' dede_archives ' SET $field = ' $value ' WHERE id= ' $aid '"; if ($dsql->executenonequery ($inQuery)) { echo "true"; Exit }else{ echo "false"; Exit } } |
Method Two, Save the draft function regularly to prevent accidental loss of data!
Introduction, the site Backstage editor is the use of Baidu Ueditor WYSIWYG editor, we are to achieve automatic timing to save the content of the editor.
The editor is called in the following way:
The code is as follows |
Copy Code |
|
Add the JS call tag at the end of the publication page or edit page:
The code is as follows |
Copy Code |
|
The code for Localstorag.js is as follows:
The code is as follows |
Copy Code |
*/* Note: This JS script should be placed in the last place of the source code of the page */ if (!window.localstorage) { Alert (' Your browser does not support Localstorage technology! '); }else{ var spanobj = document.getElementById (' s1 '); var savetimer= setinterval (function () { var str= ""; if (document.all) {/*ie*/str=document.frames[1].document.body.innerhtml;} else{/*chrome,ff*/Str=document.getelementbyid ("Ueditor_0"). ContentDocument.body.innerHTML; if (str.length>20 && (Str.indexof (". ") >-1 | | Str.indexof (",") >-1) {/* content is saved with a period or comma */ Localstorage.setitem ("Ctvalue", str); var d = new Date (); var ymdhms = d.getfullyear () + "-" + (D.getmonth () +1) + "-" + d.getdate () + "" + d.gethours () + ":" + d.getminutes () + ":" + D.getseconds (); spanobj.innertext= ' (Data stored in: ' +ymdhms+ ') '; SetTimeout (function () {spanobj.innertext= ";},5000); } },25000); Save once every n seconds function Stoplocs () { Clearinterval (Savetimer); Stop saving Localstorage.removeitem ("Ctvalue"); Empty } function Showlocs () { var html = localstorage.getitem ("Ctvalue"); Editor.setcontent (HTML); Alert (Localstorage.getitem ("Ctvalue")); } } |
You can add the Stop save button or the Restore Now button as follows:
The code is as follows |
Copy Code |
Stop saving Restore now |
Well, now your website publishing page/edit page has automatic save function. Note that this way supports IE8 and above versions of Ie,chrome,firefox and so on most mainstream browsers. As for the IE6, it is really old-fashioned and not within the scope of consideration. If you must consider IE6, use the IE6/IE7 compatibility scheme provided above.
http://www.bkjia.com/PHPjc/632717.html www.bkjia.com true http://www.bkjia.com/PHPjc/632717.html techarticle automatic saving is often used in the editor, to achieve data timing save we will use the Ajax function, below we come together to see an input box loses focus automatically save the input box data ...