Based on php (Thinkphp) + jquery, the ajax multiple-choice invert selection and data deletion functions are implemented. thinkphpjquery

Source: Internet
Author: User

Based on php (Thinkphp) + jquery, the ajax multiple-choice invert selection and data deletion functions are implemented. thinkphpjquery

We recommend that you have a js Foundation, learn about jquery and thinkphp, and use the code below if you don't talk nonsense.

---- HTML ----

// The thinkphp loop display grants the fid in data to multiple selection boxes <volist name = "data" id = "vo"> <tr> <td> <input type = "checkbox" value = "{$ vo. fid} "/> </td> // Add the td input parameter </tr> </volist> <tr> <th width =" 80 "> <input type = "checkbox" id = "all"/> select all </th> <th width = "80"> <input type = "button" value = "select all" class = "btn "id =" selectAll "/> </th> <th width =" 80 "> <input type =" button "value =" NONE "class =" btn "id = ""unSelect"/> </th> <input type = "button" value = "invert" class = "btn" id = "reverse"/> </th> <th width = "180"> <a href = "javascript: void (0); "rel =" external nofollow "onclick =" del () "title =" delete selected data "> Delete </a> </th> </tr>

---- Jsvascript ----

<Script> // multiple options $ ("# all "). click (function () {if (this. checked) {$ ("# list: checkbox "). attr ("checked", true);} else {$ ("# list: checkbox "). attr ("checked", false) ;}}); // click the "all" button at the specified time ("# selectAll "). click (function () {$ ("# list: checkbox, # all "). attr ("checked", true) ;}); // do not select $ ("# unSelect "). click (function () {$ ("# list: checkbox, # all "). attr ("checked", false) ;}); // reselect $ ("# reverse "). click (function () {$ ("# li St: checkbox "). each (function () {$ (this). attr (" checked ",! $ (This ). attr ("checked") ;}); allCheck () ;}); // delete function del () {var valArr = new Array; $ ("# list: checkbox [checked] "). each (function (I) {valArr [I] = $ (this ). val () ;}); var vals = valArr. join (','); // array conversion string if (valArr. length = 0) {alert ('select the option to delete ');} else {if (confirm ("are you sure you want to delete? After deletion, it cannot be restored. ") {Var data = {name: vals}; $. ajax ({type: "post", url: "{: U ('College/School/faculty_del ')}", // The url is the tp method (Controller/method) data: data, success: function (json) {var obj = eval ('+ json + ')'); // The returned json is converted to the js object if (parseInt (obj. counts)> 0) {alert (obj. des); location. reload ();} else {alert (obj. des) ;}}, error: function (XMLHttpRequest, textStatus) {alert ("Page request error. Please check and try again or contact the administrator! \ N "+ textStatus) ;}}}}</script>

---- PHP ----

Public function faculty_del () {$ fid = trim ($ _ POST ['name']); // The following is the query condition $ bname ['deleteark'] = 0; $ res = $ this-> faculty_model-> where (array ('fid' => array ('in', $ fid)-> save ($ bname ); // The query condition is your query condition. Here we delete it logically. Modify the field value. // echo $ this-> faculty_model-> getLastSql (); // var_dump ($ res); // exit; if ($ res) {$ counts = "1"; $ des = "successful ";} else {$ counts = "0"; $ des = "failed" ;}$ json_data = "{"; $ json_data. = "\" counts \":". json_encode ($ counts ). ","; $ json_data. = "\" des \":". json_encode ($ des ). ""; $ json_data. = "}"; echo $ json_data; exit ;}

Because it is asynchronous, the data you send is viewed on the console. The current page is not output. Do not go to the page to find it.

The above section describes how to use php (Thinkphp) + jquery to implement the ajax multiple-choice invert selection and data deletion function. I hope it will help you. If you have any questions, please leave a message, the editor will reply to you in a timely manner. Thank you very much for your support for the help House website!

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.