我有一个主选择标签“类别”,它调用php脚本来‘回显’一个新的选择标记:
<select id="category" onchange="showme(this);">
<option value="txt">text</option>
<option value="img">image</option>
<option value="htm">html</option>
<option value="aud">Audio</option>
</select>
下面是调用PHP脚本的函数:
function showme(str) {
var e = document.getElementById("country");
var str = e.options[e.selectedIndex].value;
if (str=="") {
document.getElementById("channels").innerHTML="";
return;
}
if (window.XMLHttpRequest) {
// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
} else { // code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function() {
if (this.readyState==4 && this.status==200) {
document.getElementById("channels").innerHTML=this.responseText;
}
}
xmlhttp.open("GET","lstavai.php?q="+str,true);
xmlhttp.send();
}
这里是我的PHP脚本:
<?php
$q = $_GET['q'];
$files = glob('../dsx/'.$q.'/*.txt');
echo '<select id="Subme" onchange="showSubme(this);">';
foreach($files as $file) {
$file = pathinfo($file);
echo '<option value="'.$file['basename'].'">'.$file['filename'].'</option>';
}
echo '</select>';
?>
因此,Subme
选择标记是echoed
脚本并加载到div channels
中,一切都很好,但是PHP onchange=“showSubme(This)”分配给它的函数不起作用:-(
这个showSubme函数就像showme(str) (上面给出的),并将触发一个类似的PHP脚本。
为什么它不起作用?我漏掉了什么东西吗?我感谢所有的答案!
发布于 2016-12-21 04:39:03
简单地解决以下问题:在开头添加一个禁用选项:
<?php
$q = $_GET['q'];
$files = glob('../dsx/'.$q.'/*.txt');
echo '<select id="Subme" onchange="showSubme(this);">
<option disabled selected>Please select</option>
';
foreach($files as $file) {
$file = pathinfo($file);
echo '<option value="'.$file['basename'].'">'.$file['filename'].'</option>';
}
echo '</select>';
?>
谢谢你!
发布于 2016-12-21 03:30:49
您可能需要在代码中查看以下内容:
var e = document.getElementById("country");
在html中,您调用的是id类别,而不是国家。
<select id="category" onchange="showme(this);">
快乐编码,Max
https://stackoverflow.com/questions/41261643
复制相似问题