私はいくつかの.htmlファイルのあるディレクトリを持っています。PHPのリストディレクトリ内に表示するリンク付きのHTMLファイル
ファイルのリストを選択リストに読み込み、そのファイルが選択されている場合は、そのファイルをdivに表示しますか?
jqueryなどが必要な場合は問題なく使用できます。
私はいくつかの.htmlファイルのあるディレクトリを持っています。PHPのリストディレクトリ内に表示するリンク付きのHTMLファイル
ファイルのリストを選択リストに読み込み、そのファイルが選択されている場合は、そのファイルをdivに表示しますか?
jqueryなどが必要な場合は問題なく使用できます。
phpでディレクトリを読んで、選択リストに入力する必要があります。選択したonchangeイベントよりも、選択したものを読み、必要な場所に表示する必要があります。
のiframe、
<?php
$dir = ".";
$dh = opendir($dir);
echo "<select onchange='changePage(this)'>";
while (($file = readdir($dh)) !== false) {
echo "<option value='$file'>$file</option>";
}
closedir($dh);
echo "</select>";
?>
<br />
<iframe id="f" src="" height="600" width="800" ></iframe>
<script type="text/javascript">
function changePage(e) {
var ifr = document.getElementById("f");
ifr.src = e.value;
}
</script>
ありがとうございました!それは私に素晴らしいスタートを与えるだろう!再度、感謝します! – SunBum
との単純な例で、私は上記のように純粋なjQueryと同じ考え方を使用することを選択しました。それは作品にあった、ちょうど私に数分かかった
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>File Select and Show example</title>
<script type="text/javascript" src=jquery-1.7.1.min.js"></script>
<script type="text/javascript">
$(function(){
$("#filesList").on('change', function(){
$("#showMeTheFile").empty();
var ourFile = $(this).val();
$('#showMeTheFile').load(ourFile);
});
});
</script>
</head>
<body>
<?php
$dir = "path/to/our/directory";
if (is_dir($dir)) {
if ($dh = opendir($dir)) {
//we need to build the select list before the while statement
echo '<select id="filesList">';
while (($file = readdir($dh)) !== false) {
if(filetype($dir . $file) == 'file'){
$splitFile = explode('.', $file);
if($splitFile[1] = 'html'){
echo '<option value='.$file.'>'.$splitFile[0].'.'.$splitFile[1].'</option><br/>';
}
}
}
//we also need to close it after our while statment.
echo '</select>';
closedir($dh);
}
}
?>
<div id='showMeTheFile'>
</div>
</body>
</html>
Ohgodwhy、ありがとう!それは助けになるだけでなく、素晴らしい学習ツールです。助けに時間を割いていただきありがとうございます! – SunBum
それはいいです.... –
あなたは何を疲れていますか?どこに問題がありますか? – jasonlfunk
これは質問よりも仕様に似ています。 – Corbin