2014-09-29 59 views
0

我有一組自舉下拉列表中刪除/行動的形式發佈/取消發佈的數據:在形式上PHP刪除複選框行自舉下拉菜單

<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> 

我有這個網站:

<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

您可以在標籤li添加一個字段,例如data-selected="false" ,當你點擊了li改變的狀態data-selected="true"

然後爲了檢索字段$('li[data-selected=true]'),並且爲了得到值,在$('li[data-selected=true]')內應用each