我有一個HTML表我已經更新到使用複選框可以刪除多個文件:進程隱藏字段,並計算
<table>
<thead>
<tr>
<th>Camera Name</th>
<th>Date Created</th>
<th>Video Size</th>
<th>Video Length</th>
<th>
<button type="submit" class="deletebutton" name="delete_video" value="Delete" title="Delete the selected videos" onClick="return confirm('Are you sure you want to delete?')">Delete</button><br>
<input type="checkbox" name="radioselectall" title="Select All" />
</th>
</tr>
</thead>
<tbody>
<?php
for($i=0;$i<$num_videos;$i++)
{
//do stuff
//Note: I'm looping here to build the table from the server
?>
<tr >
<td onclick="DoNav('<?php echo $url; ?>');">
<?php echo $result_videos[$i]["camera_name"]; ?>
</td>
<td onclick="DoNav('<?php echo $url; ?>');">
<?php echo setlocalTime($result_videos[$i]["video_datetime"]); ?>
</td>
<td onclick="DoNav('<?php echo $url; ?>');">
<?php echo ByteSize($result_videos[$i]["video_size"]); ?>
</td>
<td onclick="DoNav('<?php echo $url; ?>');">
<?php echo strTime($result_videos[$i]["video_length"]); ?>
</td>
<td>
<form name="myform" action="<?php echo htmlentities($_SERVER['REQUEST_URI']); ?>" method="POST">
<input type="checkbox" name="radioselect" title="Mark this video for deletion"/>
<input type="hidden" name="video_name" value="<?php echo $result_videos[$i]["video_name"]; ?>" />
</form>
</td>
</tr>
我開始先創建一些jQuery代碼的所有創建一個選擇/取消選擇表格標題中的所有按鈕,只是顯示一個測試我可以找到哪些框被選中。這一切正常:
//selectall checkboxes - select all or deselect all if top checkbox is marked in table header
$("input[name='radioselectall']").change(function()
{
if($(this).is(':checked'))
{
$("input[type='checkbox']","td").attr('checked',true);
}
else
{
$("input[type='checkbox']","td").attr('checked',false);
}
});
//process checkboxes - which ones are on
$(".deletebutton").click(function() {
$("input[name='radioselect']:checked").each(function(i){
alert(this.value);
});
});
所以我卡住的部分是我不知道從哪裏走。我需要通過所有選中視頻的所有視頻名稱(使用複選框)。 video_name
是我表單中隱藏字段的一部分。所以當我選擇刪除按鈕時,我需要將它傳遞給我的php函數。不確定如何解決這個問題。希望這是有道理的。
其實不知道我明白嗎? _POST只需要返回選中的複選框。 JavaScript代碼知道什麼是檢查,但不是服務器代碼? – Tom 2012-04-24 13:14:07
如果您給複選框輸入'$ result_videos [$ i] [「video_name」];那麼這些將作爲這些表單元素的POST數組中的鍵,給它們值1,然後檢查這個告訴你他們是否在提交時被選中。 – Ing 2012-04-24 14:45:55
哦,我明白了。我的問題是,由於佈局原因,我在表單外創建了按鈕。這意味着我需要在JavaScript中創建表單。我應該重做這個問題。感謝您的提示,因爲可以使用複選框處理。我會標記爲已解決。 – Tom 2012-04-24 18:56:30