我试图用php显示一个文件夹中的所有文件,并在每个图像旁边放置一个单选按钮。当选择一个单选按钮时,我想重新显示页面某处的图像。最终目标是拥有三个图像集合,用户可以选择三个图像并将它们一起看作三联体。显示图像onclick里面的PHP
我知道我必须实现一些onclick代码,但我不知道如何去做。
我的代码:
<?php
$dir = "image_gallery/";
//open dir
if ($opendir = opendir($dir))
{
//read dir
while (($file = readdir ($opendir)) !==FALSE)
{
if ($file!="."&&$file!=".."&&$file!="DS_Store")
echo "<img src='$dir/$file' width='200'><input type='radio' value='$file' name='filename'><br>";
//echo "<input type='radio' value='yes' name='$file' />";
}
}
?>
<input type="submit" name="submit" value="That's Right!">
</form>
</body>
</html>
我希望能够显示$ file变量的onclick,而不是阅读完所有的图像源到一个数组并在该数组的第n个条目调用。
我很欣赏任何输入。
也对工作代码的链接,http://www.evan-livingston.com/test/list.php
EDIT
非功能的代码;
<html>
<head>
<script type="text/javascript">
function listSelectedImages() {
var selected = $('input[type=radio]:checked'),
selection = $.map(selected, function(e){
return e.value;
});
$('#selection').text(selection.join(', '));
}
$('input[type=radio]').change(listSelectedImages);
</script>
</head>
<body>
<form action="bad_words.php" method=post>
<a href="../main.page.php">back to main page</a>
<br/>
<br/>
<img src='image_gallery//11.01.29.3-13.jpg' width='200'>
<input type='radio' value='11.01.29.3-13.jpg' name='filename'>
<br>
<img src='image_gallery//11.01.29.3-3.jpg' width='200'>
<input type='radio' value='11.01.29.3-3.jpg' name='filename'>
<br>
<input type="submit" name="submit" value="That's Right!">
</form>
<div id="selection"></div>
</body>
</html>
与php无关,这将不得不做的客户端 – 2011-05-29 06:45:18
我不知道这是什么意思 – evanlivingston 2011-05-29 06:57:53
你是摄影师?三联是一个相当深奥的术语...:D – 2011-05-29 19:20:35