我有一个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