thinkphpÔõÑùʵÏÖÈ«Ñ¡ºÍɾ³ý¹¦Ð§
Ò»¡¢È«Ñ¡¹¦Ð§ÊµÏÖ
1.ÔÚÊÓͼÎļþÖУ¬ÎÒÃÇÐèÒªÌí¼ÓÒ»¸öÈ«Ñ¡µÄ°´Å¥£¬ÀàËÆÓÚÏÂÃæÕâÑùµÄ´úÂ룺
<input type="checkbox" name="chkall" onclick="check_all(this)">
µÇ¼ºó¸´ÖÆ
ÆäÖУ¬check_all()º¯ÊýµÄ×÷ÓÃÊÇÈ«Ñ¡»ò×÷·ÏÈ«Ñ¡£º
function check_all(obj){ $(':checkbox').prop('checked', $(obj).prop('checked')); }
µÇ¼ºó¸´ÖÆ
ÔÚÕâÀÓõ½ÁËjQueryµÄÑ¡ÔñÆ÷Ñ¡ÔñËùÓеÄcheckbox²¢Ê¹ÓÃprop()ÒªÁìÉèÖÃÆächeckedÊôÐÔ¡£
Á¬Ã¦Ñ§Ï°¡°PHPÃâ·ÑѧϰÌõ¼Ç£¨ÉîÈ룩¡±£»
2.ÒÔThinkPHPΪÀý£¬ÎÒÃǼÙÉèÒѾ»ñÈ¡µ½ÁËÐèÒª¾ÙÐÐÈ«Ñ¡µÄÊý¾Ý£¬²¢½«Æäת´ïµ½ÊÓͼҳÃæÖУ¬´ËʱÎÒÃÇÐèҪʹÓÃforÑ»·±éÀúÿ¸öÊý¾Ý£¬²¢ÎªÆäÌí¼ÓcheckboxºÍID£¬´úÂëÈçÏ£º
<?php foreach($list as $data):?> <tr> <td><input type="checkbox" name="ckb[]" value="<?php echo $data['id'];?>" ></td> <td><?php echo $data['title'];?></td> </tr> <?php endforeach;?>
µÇ¼ºó¸´ÖÆ
ÔÚÕâÀΪÁËÀû±ã²Ù×÷£¬Ê¹ÓÃÁËÊý×éת´ïcheckboxµÄÖµ£¬checkboxµÄÃû³ÆΪckb[]£¬Æä¶ÔÓ¦µÄvalueΪ¸ÃÐÐÊý¾ÝµÄIDÖµ¡£
3.´ËʱÎÒÃÇÖ»ÐèÒªÔÚÌá½»±íµ¥µÄʱ¼ä»ñÈ¡µ½ËùÓÐÑ¡ÖеÄcheckbox²¢½«Æä¶ÔÓ¦µÄÖµ×éºÏ³ÉÒ»¸öеÄÊý×飬¾Í¿ÉÒÔʵÏÖÈ«Ñ¡µÄ¹¦Ð§ÁË¡£ÏêϸʵÏÖ´úÂëÈçÏ£º
public function all(){ $ids = input('post.ckb/a'); if(empty($ids)){ return $this->error('ÇëѡժҪɾ³ýµÄÊý¾Ý£¡'); } $ids = implode(',',$ids); $where['id'] = array('in',$ids); $result = db('table')->where($where)->delete(); if($result){ return $this->success('ɾ³ýÀֳɣ¡'); }else{ return $this->error('ɾ³ýʧ°Ü£¡'); } }
µÇ¼ºó¸´ÖÆ
ÔÚÕâÀinput(‘post.ckb/a’)ÓÃÓÚ»ñÈ¡Ìá½»±íµ¥Ê±×ª´ïµÄËùÓÐcheckboxµÄÖµ£¬Ê¹ÓÃimplode()ÒªÁ콫ÆäÅþÁ¬³É×Ö·û´®£¬²¢½«ÆäÓÃÓÚÅÌÎÊÊý¾Ý¿âÖеÄÊý¾Ý¡£
¶þ¡¢ÅúÁ¿É¾³ý¹¦Ð§ÊµÏÖ
ʵÏÖÅúÁ¿É¾³ý¹¦Ð§ÐèҪ͎áÇ°ÃæµÄÈ«Ñ¡¹¦Ð§£¬Ïêϸ°ì·¨ÈçÏ£º
1.Ê×ÏÈ£¬Óû§ÐèҪѡÖÐÐèҪɾ³ýµÄÊý¾Ý£¬È»ºóµã»÷ɾ³ý°´Å¥£¨»òÆäËû×Ô½ç˵°´Å¥£©£¬ÕâʱÐèÒª»ñÈ¡Ñ¡ÖеÄÊý¾Ý²¢¶ÔÆä¾ÙÐÐɾ³ý²Ù×÷¡£
2.ΪÁËÀû±ã²Ù×÷£¬ÎÒÃÇ¿ÉÒÔ½«ËùÓÐÑ¡ÖеÄÊý¾ÝIDÖµºÏ²¢³ÉÒ»¸ö×Ö·û´®£¨ÒÔÓ¢ÎĶººÅÍÑÀ룩£¬È»ºó½«Æäת´ïµ½ÏÂÒ»¸ö´¦Àíº¯ÊýÖС£
3.ʹÓÃwhere()º¯Êý½«É¾³ýÌõ¼þÉèÖÃΪid in (ids)£¨ÆäÖУ¬idsΪËùÓÐҪɾ³ýÊý¾ÝµÄID£©£¬È»ºóʹÓÃdelete()º¯Êýɾ³ýÖª×ãÌõ¼þµÄÊý¾Ý¼´¿É¡£
ÏêϸʵÏÖ´úÂëÈçÏ£º
public function delete(){ $ids = input('post.ids/s',''); if(empty($ids)){ return $this->error('ÇëѡժҪɾ³ýµÄÊý¾Ý£¡'); } $where['id'] = array('in',$ids); $result = db('table')->where($where)->delete(); if($result){ return $this->success('ɾ³ýÀֳɣ¡'); }else{ return $this->error('ɾ³ýʧ°Ü£¡'); } }
µÇ¼ºó¸´ÖÆ
ÒÔÉϾÍÊÇthinkphpÔõÑùʵÏÖÈ«Ñ¡ºÍɾ³ý¹¦Ð§µÄÏêϸÄÚÈÝ£¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡