|
html代码:
<tr>
<td><input type="checkbox" name="uid" value="<?=$item['mtaccount_id']?>"></td>
<td><?=$item['mtaccount_id']?></td>
<td><?=$item['account_id']?></td>
<td><?=$item['account_name']?></td>
<td><?=$item['server']?></td>
<td><?=$item['platform']?></td>
</tr>
我的是html里的数据是从数据库读出来的,在此可以理解为下面代码
<li><input type="checkbox" name="uid" value="1" />用户1</li>
<li><input type="checkbox" name="uid" value="2" />用户2</li>
<li><input type="checkbox" name="uid" value="3" />用户3</li>
<li><input type="checkbox" name="uid" value="4" />用户4</li>
jquery代码:
1 var mt4Ids = [];
2 $('input[name=uid]').each(function() {
3 if(this.checked) {
4 mt4Ids.push($(this).val());
5 }
6 });
7 data = {
8 mt4Ids : JSON.stringify(mt4Ids)
9 };
10 var pUrl = "/a/manageUser.html";
11 $.post(pUrl, data, function(data){
12 if(data.state == 1){
13 alert(data.msg);
14 location.href = "/h/permission.html";
15 }else{
16 alert("操作失败");
17 }
18 }, 'json');
PHP代码
1 $mt4Ids = !empty($_POST['mt4Ids']) ? $_POST['mt4Ids'] : false;
2
3 $stripMt4Ids = preg_replace('/[\"\[\]]/', '', $mt4Ids);
4 $mt4IdsToArr = explode(',', $stripMt4Ids);
5
6 foreach($mt4IdsToArr as $uid){
7 permission_relation::add($uid, $gid);
8 }
9 $data = array(
10 'state' => 1,
11 'msg' => '操作成功'
12 );
13 echo json_encode($data);
14 return false;
// $gid 可忽略
|
|
|