[英]Listing files in a dropdown menu linking to these
我希望出現一個下拉菜單,其中列出了我在目錄中擁有的所有PDF文件,並使每個條目都可單擊,從而鏈接到特定文件。
我已經嘗試了很多,實際上顯示了帶有列出的PDF的下拉菜單,但是當我嘗試在其旁邊添加一個Button來打開包含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()">
現在您可以選擇一個文件,單擊按鈕並重定向。
現在在此處獲取更多信息:首先,沒有關閉選項標簽(可能由瀏覽器自動關閉),因此您在一個HTML標簽中具有了file1,file2等。 (沒有區別,因為我在沒有封閉的選項標簽的情況下進行了測試)
如果要對文件名使用onclick,則需要更正函數以獲取輸入,lemme會為您提供示例: <input type="button" class="button-spec" value="Visit Link!" onclick="goToNewPage(document.getElementById('target').value)">
<input type="button" class="button-spec" value="Visit Link!" onclick="goToNewPage(document.getElementById('target').value)">
function goToNewPage(newPageUrl){window.location.href = newPageUrl;}
希望這可以幫助 :)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.