我有一个select元素,我使用ajax填充文件名。
HTML是:
<select id='load_dropdown' name=loads help_token="load_dropdown" title="">
<option value='' selected='selected'>LOAD</option>
</select>
填充元素的调用是:
$('select#load_dropdown') .load('getFiles.php', {list : 'LOAD'}); //fill the load drop down list
getFiles.php:是
$dir = $_SESSION['user']['id'] . "/xmls/"; // files are in xmls dir
if ($dirHandle = opendir($dir) ){
}
else {
echo ("<br />getFiles.php: $dir not found.");
exit;
}
echo ("<option selected='selected' value=''><b> $list </b> </option>"); // first line of this drop down option
while (false !== ($fileName = readdir($dirHandle))) {
if ($fileName == "." || $fileName == "..") {
continue;
}
$fileNames[] = $fileName; // collect file names
}
sort($fileNames);
foreach ($fileNames as $fileName) {
$displayName = basename($fileName, '.xml'); // cut .xml at end
echo ("<option value='$displayName'>" . $displayName . "</option>");
}
}
这适用于Firefox,Chrome,Safari和IE10。它不适用于IE9。
使用IE9时,select元素不会填充加载的信息,但我可以看到getFiles.php调用正在返回正确的数据。在调用之后,select元素是
有谁知道IE9会发生什么?
感谢。
答案 0 :(得分:1)
我有同样的问题。更好的方法是引用div
和span
元素:
<div id="select"><select id='load_dropdown' name=loads help_token="load_dropdown" title="">
<option value='' selected='selected'>LOAD</option>
</select>
</div>
-
$('#select #load_dropdown') .load('getFiles.php', {list : 'LOAD'}); //fill the load drop down list
答案 1 :(得分:1)
你的jquery版本是什么? 我用1.9.1和1.10.2测试了这段代码:
getFiles.php:
<?php
//$dir = $_SESSION['user']['id'] . "/xmls/"; // files are in xmls dir
$dir = 'xmls/'; // for testing
if ($dirHandle = opendir($dir) ){
} else {
echo ("<br />getFiles.php: $dir not found.");
exit;
}
echo ("<option selected='selected' value=''><b> $list </b> </option>"); // first line of this drop down option
while (false !== ($fileName = readdir($dirHandle))) {
if ($fileName == "." || $fileName == "..") {
continue;
}
$fileNames[] = $fileName; // collect file names
}
sort($fileNames);
foreach ($fileNames as $fileName) {
$displayName = basename($fileName, '.xml'); // cut .xml at end
echo ("<option value='$displayName'>" . $displayName . "</option>");
}
<强> get_files.html 强>
<script src="jquery-1.10.2.min.js" type="text/javascript"></script>
<select id='load_dropdown' name=loads help_token="load_dropdown" title="">
<option value='LOAD' selected='selected'>LOAD</option>
</select>
<script>
$('select#load_dropdown').load('getFiles.php', {list : 'LOAD'}); //fill the load drop down list
</script>
我已使用xmls
和file1.xml
在项目的根目录中创建了一个file2.xml
文件夹。
适用于IE9(版本9.0.8112。更新9.0.24)(与其他浏览器相同)。列表框包含file1
和file2
:
如果你想看到生成的html,你必须点击刷新按钮(在红色方块)
希望这就是你想要的。