我希望有一个下拉菜单出现,其中列出所有PDF文件我有一个目录,使每个条目点击,链接到特定文件。
我已经尝试了很多,其实与上市显示了PDF格式的下拉菜单,但是当我尝试添加一个按钮旁边打开一个新页面的PDF文件,但点击它的时候,没有什么会发生在所有
<select name="PdfFile" id="target" class="pdfliste">
<option value="">- Wähle Datei -
<?php
$dirPath = dir('beispiel');
$imgArray = array();
while (($file = $dirPath->read()) !== false)
{
$imgArray[ ] = trim($file);
}
$dirPath->close();
sort($imgArray);
$c = count($imgArray);
for($i=0; $i<$c; $i++)
{
echo "<option value=\"" . $imgArray[$i] . "\">" . $imgArray[$i] . "\n";
}
?>
</select>
<input type="button" class="button-spec" value="Visit Link!"
onclick="goToNewPage(document.dropdown.PdfFile)">';
JAVASCRIPT
function goToNewPage() {
if(document.getElementById('target').value) {
window.location.href = document.getElementById('target').value;
}
}
我现在发现了两件事情:
echo "<option value=\"" . $imgArray[$i] . "\">" . $imgArray[$i] . "</option>\n";
<input type="button" class="button-spec" value="Visit Link!"
onclick="goToNewPage()">
现在,你可以选择一个文件,点击按钮和重定向。
现在这里的更多信息:首先,期权代码没有被封闭(也许通过浏览器自动),而是让你有文件1,文件2,等在一个HTML标签。 (没有什么区别,我测试了它不封闭的选项标签)
如果您想使用这些文件的onclick名字,你将需要纠正功能,因此它的输入,还是让我给你的是,例如:
<input type="button" class="button-spec" value="Visit Link!"
onclick="goToNewPage(document.getElementById('target').value)">
function goToNewPage(newPageUrl){window.location.href = newPageUrl;}
希望这可以帮助 :)