JQuery + php implements the all-selected deletion method, and jqueryphp Selects all

Source: Internet
Author: User

JQuery + php implements the all-selected deletion method, and jqueryphp Selects all

The example in this article describes how jQuery + php simply implements all-selected deletion. We will share this with you for your reference. The details are as follows:

<Input type = "checkbox" id = "ckb_selectAll" onclick = "selectAll ()" title = "select/deselect"> <a href = "javascript: void (0 ); "onclick =" del _ () "title =" delete selected data "style =" font-weight: normal "> Delete </a>

Select all checkpoints.

<input type="checkbox" class="ckb" id="+con.id+" value="+con.id+">

The identifier is the delete item, and the same class is named ckb, which facilitates operations. Meanwhile, the id value is cleverly placed in the input for easy acquisition.

Function selectAll () {if ($ ('# ckb_selectAll '). is (': checked') {$ (". ckb "). attr ("checked", true); // select all} else {$ (". ckb "). attr ("checked", false); // cancel all }}

Selected events

Function del _ () {var ids = ''; $ (". ckb "). each (function () {if ($ (this ). is (': checked') {ids + =', '+ $ (this ). val (); // obtain ids one by one}); ids = ids. substring (1); // process the id and remove the first comma if (ids. length = 0) {alert ('select the option to delete ');} else {if (confirm ("are you sure you want to delete? After deletion, it cannot be restored. ") {Url =" action = del_call_record & ids = "+ ids; $. ajax ({type: "post", url: "send. php ", data: url, success: function (json) {if (parseInt (json. counts)> 0) {alert (json. des); location. reload ();} else {alert (json. des) ;}}, error: function (XMLHttpRequest, textStatus) {alert ("Page request error. Please check and try again or contact the administrator! \ N "+ textStatus );}});}}}

Callback deletion is handled using ajax.

↓ Operations on the database in the background to process deletion actions.

$ Ids = trim ($ _ REQUEST ['id']); $ del_ SQL = "DELETE FROM vicidial_call_record WHERE id IN (". $ ids. ")"; // print_r ($ del_ SQL); exit; if (mysqli_query ($ db_conn, $ del_ SQL) {$ 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; break;

Complete

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.