When we are doing a site often encounter bulk Delete this option, in fact, it is very simple, we need to use JQ to achieve the effect and then through the form post past the backend can be achieved:
Before we do this, we must first introduce JQ, and my JQ version is 1.8.3, as shown in the following method:
<script> // in JQ 1.8.3 test successful $ ("#selall"). Click (function() { if ($ (this). attr ("checked")) { $ ('. Selall '). attr ("Checked", "checked"); } Else { $ ('. Selall '). Removeattr ("checked"); } ); </script>
Then look at the page effect:
First, the effect is realized, and then the next step, the action of the Lists.html form form is modified to modify it to
And then come to the controller to create one more Tdel method,
Then modify the value of the next lists.html,
If we choose more, we'll use an array to receive the ar_id.
After clicking OK to delete, we can receive an array on the backend as follows:
In order to prevent accidental deletion, we can add a piece of code in the confirmation delete:
onclick= "return confirm (' Are you sure you want to delete this column? ‘);"
This will automatically pop up a dialog box when someone clicks Delete, the effect is as follows:
The next step is to go back to the array we are going to use to implode her, and then he becomes a string form:
Public functionTdel () {$tdel= I ("Tdel"); $tdel=implode(‘,‘,$tdel);//implode let the array split into string form//dump ($tdel); $mod= M (' article '); if($mod->delete ($tdel)){ $this->success (' Delete succeeded '); }Else{ $this->success (' Delete failed '); } }
This allows for bulk deletion.
Kill lui Lei dog thinkphp project----Enterprise website 16 article bulk Delete completion