Recently in the background function development, used to modify the sort field, feel just to modify a sort value, and to re-enter the edit page more trouble, so the Internet to find some information on their own hands to write a jquery double click to achieve the effect of directly modifying the sorted values:
HTML code:
<div title= "" Double-click to modify directly class= Changesort id= "{$id}" >{$sort}</div>
JS Code:
<script type= "Text/javascript" >
//Double-click Modify Sort
$ ('. Changesort '). DblClick (function () {
var url = ' {: U ' Setsort ')} ";
var td = $ (this);
var id = td.attr (' id ');
var text = Td.text ();
var txt = $ ("<input type= ' text ' class= ' Input-small ' >"). val (text);
Txt.blur (function () {
//lose focus, save value. Write to the server interactively, preferably ajax
var NewText = $ (this). Val ();
$.ajax ({
url:url,
type: ' POST ',
data:{' tid ': id, ' sort ': NewText},
dataType: ' JSON '
, Success:function (res) {
if (res.flag==1) {
layer.msg (res.msg);
Remove the text box and display the new value
$ (this). Remove ();
Td.text (NewText);
} else if (res.flag==3) {
layer.msg (res.msg);
Txt.val (NewText)
;}}); Td.text ("");
Td.append (TXT);
});
</script>
PHP Code:
? PHP
/**
* Ajax Set Sort value */public
function Setsort () {
if (is_post) {
$tid = I (' Post.tid ');
$sort = I (' Post.sort ');
if (!is_numeric ($sort)) {
$arr = array (
' flag ' =>3,
' msg ' => ' Please enter a number ', '
link ' => ',
' Content ' => '
);
$this->ajaxreturn ($arr);
}
$data = Array (
' id ' => $tid,
' sort ' => $sort
);
$this->mod_sort = M (' sort ');
$res = $this->mod_sort->save ($data);
if ($res) {
$arr = array (
' flag ' =>1,
' msg ' => ' sort value set successfully ',
' link ' => ',
' content ' = > "
);
else{
$arr = array (
' flag ' =>2, '
msg ' => ' sort value setting failed ', '
link ' => ',
' content ' => ')
);
}
} else{
$arr = array (
' flag ' =>0,
' msg ' => ' request illegal!) ', '
link ' => ',
' content ' => '
);
}
$this->ajaxreturn ($arr);
>
The effect of the following figure:
The above is the entire content of this article, I hope to help you learn.