我有以动作形式设置删除/发布/取消发布数据的引导下拉列表:
<div class="col-sm-7">
<ul class="list-unstyled topControl">
<li id="bulkAction">
<div class="btn-group">
<button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown">Select Action <span class="caret"></span>
</button>
<ul class="dropdown-menu" role="menu">
<li data-action="3"><a href="#">Delete</a>
</li>
<li data-action="1"><a href="#">Publish</a>
</li>
<li data-action="0"><a href="#">Unpublish</a>
</li>
</ul>
</div>
</li>
</ul>
</div>
在形式上我有这个html:
<tr>
<td>
<input type="checkbox" name="id[]" class="itemCheckBox" value="6" />
</td>
<td>2323</td>
<td>Project</td>
<td>09-19-2014</td>
<td> <a href="" class="label label-success">Published</a>
</td>
<td> <a class="btn btn-info btn-xs" href="" title="Edit post"><i class="icon-edit"></i></a>
<a class="btn btn-danger btn-xs confirmationDelete" href="" title="Delete post"><i class="icon-trash"></i></a>
</td>
</tr>
<tr>
<td>
<input type="checkbox" name="id[]" class="itemCheckBox" value="5" />
</td>
<td>2323</td>
<td>Project</td>
<td>09-19-2014</td>
<td> <a href="" class="label label-success">Published</a>
</td>
<td> <a class="btn btn-info btn-xs" href="" title="Edit post"><i class="icon-edit"></i></a>
<a class="btn btn-danger btn-xs confirmationDelete" href="" title="Delete post"><i class="icon-trash"></i></a>
</td>
</tr>
现在我需要选中复选框中的文章(一行或多行),而不是单击下拉菜单(示例删除)时我的表单处理这个并使用PHP从数据库中删除行,如下所示:
if ($_POST['action'] == "delete")
{
$selected = $_POST['id'];
if (count($_POST['id']) !== 0)
{
foreach($selected as $uid)
{
SQL::DELETE("DELETE FROM " . NEWS_ARTICLES . " WHERE id = ?", $uid);
}
echo "<div class=\"success\">" . $langmsg['editnews'][17] . "</div>";
}
}
我该如何创建?!
答案 0 :(得分:0)
您可以在标签li
中添加其他字段,例如data-selected="false"
当您点击li
时,会更改状态data-selected="true"
。
然后检索字段$('li[data-selected=true]')
,并获取值each
在$('li[data-selected=true]')
内。