PHP
·
发表于 5年以前
·
阅读量:8298
±¾ÎÄʵÀýÖÎoÁË»uÓÚThinkPHPʵÏÖÅuÁ¿É¾³ýµÄ´uÂeʵÀý£¬ÖÏi¸ø´o¼Ò¹(C)´o¼Ò²Î¿¼£¬¾ßÌaÈçÏ£º
*Ï»°²»¶a˵£¬ÏÈÉÏЧ¹uͼ£º
HTML²¼¾Ö£¨»uÓÚbootstrap£(C)
<div class="panel panel-default">
<div class="panel-heading">
ÁoÑÔÁбi
<a class="btn btn-xs btn-default pull-right" href="javascript:window.history.back();">*µ»Ø</a>
<a class="btn btn-xs btn-info pull-right mr-5" id="discard" href="javascript:;">ɾ³ý</a>
</div>
<table class="table">
<thead>
<tr>
<th><input class="all" type="checkbox"/></th>
<th>id</th>
<th>Ãu³Æ</th>
<th>ÓÊÏa</th>
<th>ÄÚÈÝ</th>
<th>ÈÕÆÚʱ¼a</th>
<th>²Ù×÷</th>
</tr>
</thead>
<tbody>
<form>
<volist name="list" id="vo" empty="$empty">
<tr>
<td><input name="delete[]" type="checkbox" value="{$vo.id}" /></td>
<td>{$vo.id}</td>
<td>{$vo.name}</td>
<td>{$vo.email}</td>
<td>{$vo.subject}</td>
<td>{$vo.datetime|date="Y-m-d H:i", ###}</td>
<td>
<a class="delete" href="javascript:;" data-id="{$vo.id}">ɾ³ý</a>
</td>
</tr>
</volist>
</form>
</tbody>
</table>
</div>
JS½Å±¾´¦Ài£¨Ê¹ÓÃajax¼¼Êo£(C)
Ê×ÏÈÅжÏÓÐûÓÐÑ¡ÖеÄÖµ£¬Èç¹uûÓÐÔoÌaʾ£»Èç¹uÓУ¬Ôo´«µÝµ½*þÎñÆ÷¶Ë´¦Ài
/* ÅuÁ¿É¾³ý */
// È«Ñ¡
$('.all').click(function() {
if($(this).is(':checked')) {
$(':checkbox').attr('checked', 'checked');
} else {
$(':checkbox').removeAttr('checked');
}
});
// ɾ³ý²Ù×÷
$('#discard').click(function() {
if($(':checked').size() > 0) {
layer.confirm('È*¶¨ÒªÉ¾³ýÂð£¿', {
btn: ['È*¶¨','È¡Ïu'], //°´Å¥
shade: false //²»ÏÔʾÕÚÕÖ
}, function(){
$.post("{:U('Single/discard')}", {data: $('form').serializeArray()}, function(res) {
if(res.state == 1) {
layer.msg(res.message, {icon: 1, time: 1000});
} else {
layer.msg(res.message, {icon: 2, time: 1000});
}
setTimeout(function() {
location.reload();
}, 1000);
});
}, function(){
layer.msg('È¡ÏuÁËɾ³ý£¡', {time: 1000});
});
} else {
layer.alert('ûÓÐÑ¡Ôñ£¡');
}
});
PHP´uÂe£º
»ñÈ¡Ìa½»µÄÊý¾Ý£¬È»ºoÑ»*µÃµ½Ã¿Ò»¸oidµÄÖµ£¬½Ó׎øÐÐɾ³ý²Ù×÷¡£
public function discard() {
$contact = M('contact');
$deleteArr = I('post.data');
for($i=0;$i<count($deleteArr);$i++) {
$contact->delete($deleteArr[$i]['value']);
}
$this->ajaxReturn(array('message'=>'ɾ³ý³É¹¦£¡'));
}
ÒÔÉϾÍÊÇThinkPHPʵÏÖÅuÁ¿É¾³ýµÄ¹Ø¼uÐÔ´uÂe£¬Ï£Íu¶Ô´o¼ÒµÄѧϰÓÐËu°iÖu¡£