<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd">
<html>
<head>
<script type="text/javascript">
function selectSomething(){
var obj = document.all.select1;
var selectValue = obj.options[obj.selectedIndex].value;
if(selectValue == "1"){
document.getElementById("text").innerHTML ="one";
}
if(selectValue == "2"){
document.getElementById("text").innerHTML ="two";
}
}
</script>
</head>
<body onload="selectSomething()">
<select id="select1" onchange="selectSomething()">
<option value="1">One</option>
<option value="2">Two</option>
</select>
<div id="text"></div>
</body>
</html>
此代码适用于 Chrome 17.0.963.83、IE 8.0.6001.18702,但不适用于 Firefox 11.0。除非我删除 DOCTYPE,否则 insidehtml 永远不会在 Firefox 中显示,但我无法删除该 DOCTYPE,因为该网页将是更大项目的一部分。这是 Firefox 的错误吗?如何在 Firefox 中实现此功能?
最佳答案
看看 Firefox 错误控制台(对于 Web 开发人员来说非常有用)。在 Firefox 中,document.all
未定义。
相反,您应该使用document.getElementById("select1")
。
关于javascript - innerhtml firefox 不支持 Doc 类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9889775/