仅第一个复选框有效 - 其他检查仅在选中第一个复选框时才有效


Only first check works - others only work if first check box is selected

script language="javascript" type="text/javascript">
function moveNumbers(num) { 
if(document.getElementById("selector").checked){
var txt=document.getElementById("result").value; 
txt=txt + num; 
document.getElementById("result").value=txt; 
}
else{
document.getElementById("result").value=txt="";
}
} 
</script>
<textarea id="result" name="image_id" rows="8" cols="11" readonly>
</textarea>
<tr>
<?php
$path = "photos/";
$dir_handle = @opendir($path) or die("Unable to open folder");
echo "<table height='500px'width='800px'align='center'border='1'>";
echo "<tr>";
while (false !== ($file = readdir($dir_handle))) {
if($file == "index.php")
continue;
if($file == ".")
continue;
if($file == "..")
continue;
{
echo ($x % 6 == 0) ? "</tr><tr>" : "";
echo "<td><input type='checkbox' id='selector' value='$file'        onclick='moveNumbers(this.value)'>
<img src='photos/$file'alt='$file' style='height:auto;width:50%;'alt='$file'>
<br>
$file
</td>";
$x++;
}
}
echo "</tr>";
echo "</table>";
closedir($dir_handle);
?>

大家好,复选框有点麻烦。PHP 部分列出了图像文件,旁边带有复选框。我遇到的问题是,只有列表中带有复选框的第一个图像才会将文本输入添加到文本区域。选中第一个复选框后,其他复选框是否有效?有什么想法吗?干杯。

你在javascript中使用它:

if(document.getElementById("selector").checked){

你所有的复选框都有相同的 ID #selector所以你的 javascript 将使用它找到的第一个。请注意,您的 html 中不能有重复的 ID。