Recently do an input box lost focus automatically save the data function, of course, is the jquery selector selection Input,blur, Ajax submission data to PHP files, php file to save the data slightly. The main thing is to pay attention to the Chinese problem, so the middle need to turn the code.
The following example is a list page, a bit like Excel.
HTML code:
The code is as follows |
Copy Code |
<table width= "100%" align= "left" border= "0″cellspacing=" 0″bgcolor= "#CCCCCC" > <tr onmouseover= "This.classname= '"; "onmouseout=" this.classname= "align=" center "id=" {$id} "bgcolor=" #FFFFFF "> <TD >{$id}</td> <TD ><input type= "text" id= "title_{$id}" value= "{$title}" onblur= "Ajaxedit (' {$id} ', ' title ');" ></td > <TD ><textarea id= "description_{$id}" rows= "4″onblur=" Ajaxedit (' {$id} ', ' description '); ">{$description }</textarea></td> <TD ><a href= "view.php?aid={$id}" target= "_blank" > Preview </a><a href= "edit.php?aid={$id}" > Edit </a></td> </tr> </table> |
JS Code:
code is as follows |
copy code |
<script Type= "Text/javascript" Function Dd (i) {return document.getElementById (i);} Function Ajaxedit (aid,field) { var value = decodeURI (Dd (field+ "_" +aid). Value); $.ajax ({ Type: "POST", URL: "edit.php", Data: {dopost: "Ajaxsave", Aid:aid,field:field,value:value}, Success:function (data) { if (data== "true") {//update succeeded Dd (field+ "_" +aid). style.border= "#fff"; } else{//update failed Alert ("Update failed, may be too slow"); } }); } </script> PHP code: (a function, method referenced Dedecms) if ($dopost = = ' Ajaxsave ') { $value = UrlDecode (Autocharset ($value, "Utf-8″," Gb2312″)); //Update primary table $inQuery = "Update ' #@__archives ' SET $field = ' $value ' WHERE id= ' $aid '; if ($dsql-> Executenonequery ($inQuery))//www.111cn.net { echo "true"; Exit; } Else{ Echo false; exit; } } |