Based on PHP (thinkphp) +jquery implementation Ajax Multi-Select, reverse Select, delete data is not selected novice learning to

Source: Internet
Author: User

jquery multi-Select source source material Fire http://www.sucaihuo.com/

(There is any problem can be personal e-mail [email protected], also can add QQ to show when you can)

Suggested have JS Foundation, understand jquery,thinkphp, nonsense don't say more below on code

"———— HTML ————"

1 //thinkphp Loop shows the FID of data in the multi box2 <volistname= "Data"ID= "Vo">3 <TR>4       <TD><inputtype= "checkbox"value= "{$vo. FID}"/></TD>//can be added in the following TD input parameters    5 </TR>6 </volist>7 <TR>8 <thwidth= "a"><inputtype= "checkbox"ID= "All"/>Select All</th>9 <thwidth= "a"><inputtype= "button"value= "Select All"class= "BTN"ID= "SelectAll" /></th>Ten <thwidth= "a"><inputtype= "button"value= "All is not selected"class= "BTN"ID= "Unselect" /></th> One <th><inputtype= "button"value= "Reverse Selection"class= "BTN"ID= "Reverse" /></th>  A <thwidth= " the"> -   <ahref= "javascript:void (0);"onclick= "del ()"title= "Delete selected data">Delete</a> - </th>  the </TR>

"———— jsvascript ————"

1<script>2         //Multi-Select3$ ("#all"). Click (function(){     4         if( This. Checked) {     5$ ("#list: CheckBox"). attr ("Checked",true); 6}Else{     7$ ("#list: CheckBox"). attr ("Checked",false); 8             }     9         });Ten         //when point to select All button One$ ("#selectAll"). Click (function () {   A$ ("#list: CheckBox, #all"). attr ("Checked",true);  -         }); -         //all do not choose the$ ("#unSelect"). Click (function () {     -$ ("#list: CheckBox, #all"). attr ("Checked",false);  -         }); -         //Inverse Selection +$ ("#reverse"). Click (function () {    -$ ("#list: CheckBox"). each (function () {     +$( This). attr ("Checked",!$ ( This). attr ("Checked"));  A             });  at Allcheck ();  -         }); -         //Delete -         functiondel () { -             varValarr =NewArray; -$ ("#list: checkbox[checked]"). each (function(i) { inValarr[i] = $ ( This). Val ();  -            }); to            varVals = Valarr.join (', ');//array to convert a comma-separated string +             if(Valarr.length = = 0) { -Alert (' Please select options to delete '); the}Else{ *                 if(Confirm ("OK to delete?") It will not be recoverable after deletion. ")){ $                     varData={name:vals};Panax Notoginseng $.ajax ({ -Type: "POST", theURL: "{: U (' College/school/faculty_del ')}",//url for TP method (Controller/method)
+ Data:data, ASuccessfunction(JSON) { the varobj = eval (' (' + JSON + ') ');// return JSON to JS object + if(parseint (obj.counts) > 0) { - alert (obj.des); $ location.reload (); $}Else { - alert (obj.des); - } the }, -Errorfunction(XMLHttpRequest, textstatus) {WuyiAlert ("Page request error, please check retry or contact administrator!") \ n "+textstatus); the } - }); Wu } - } About $ } -</script>

"———— PHP ————"

1      Public functionFaculty_del () {2         $fid=Trim($_post[' Name ']);3         //The following are the query criteria4         $bname[' deletemark '] = 0;5         $res=$this->faculty_model
->where (Array(' FID ' =Array(' in ',$fid)))
->save ($bname);
Query criteria for your query criteria, my side for the tombstone, modify the field value is good6 //echo $this->faculty_model->getlastsql ();7 //Var_dump ($res);8 //exit;9 if($res) {Ten $counts= "1"; One $des= "Success"; A}Else { - $counts= "0"; - $des= "Failed"; the } - $json _data= "{"; - $json _data. = "\" counts\ ":". Json_encode ($counts).","; - $json _data. = "\" des\ ":". Json_encode ($des).""; + $json _data.= "}"; - Echo $json _data; + Exit; A}

Because it is asynchronous so you send the data are in the console view, the current page is not output, do not go to the page to find (do not ask me why I know, I did, think of really stupid)

Based on PHP (thinkphp) +jquery implementation Ajax Multi-Select, reverse Select, delete data is not selected novice learning to

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.