JavaScript在IE可以正常运行,在火狐不能,请教怎么修改?
<scriptlanguage="JavaScript"><!--varstreet=newArray(newArray("Authorware多媒体课件制作","Aut...
<script language="JavaScript">
<!--
var street = new Array(new Array("Authorware多媒体课件制作", "Authorwar游戏开发"),
new Array("flash网站制作", "flash小游戏制作"),
);
function showStreet(blah) {
removeAll();
index = blah.selectedIndex - 1;
for(i=0;i<street[index].length;i++) {
var oOpt = document.createElement("OPTION");
document.all.street.options.add(oOpt);
oOpt.innerText = street[index][i];
}
}
function removeAll() {
count = document.all.street.options.length;
for(i=0;i<count;i++) {
document.all.street.options.remove(0);
}
}
//-->
</script>
<select name=district onchange="showStreet(this)">
<option>==请选择==
<option>王芸
<option>李冬
</select>
<select name=street>
</select> 展开
<!--
var street = new Array(new Array("Authorware多媒体课件制作", "Authorwar游戏开发"),
new Array("flash网站制作", "flash小游戏制作"),
);
function showStreet(blah) {
removeAll();
index = blah.selectedIndex - 1;
for(i=0;i<street[index].length;i++) {
var oOpt = document.createElement("OPTION");
document.all.street.options.add(oOpt);
oOpt.innerText = street[index][i];
}
}
function removeAll() {
count = document.all.street.options.length;
for(i=0;i<count;i++) {
document.all.street.options.remove(0);
}
}
//-->
</script>
<select name=district onchange="showStreet(this)">
<option>==请选择==
<option>王芸
<option>李冬
</select>
<select name=street>
</select> 展开
1个回答
展开全部
火狐不支持document.all
给后面name为street的那个设一个ID为street然后通过document.getElementById('street')来取得这个select对象
你的写法一点都不符合W3C标准.所以以后一定要写符合W3C标准的.这样火狐就不会出问题了.下面是我给你写的你看看
<!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>无标题文档</title>
</head>
<body>
<script language="JavaScript">
<!--
var street = new Array(new Array("Authorware多媒体课件制作", "Authorwar游戏开发"),
new Array("flash网站制作", "flash小游戏制作"));
function showStreet(blah) {
removeAll();
index = blah.selectedIndex - 1;
for(i=0;i<street[index].length;i++) {
document.getElementById('street').options.add(new Option(street[index][i]));
}
}
function removeAll() {
count = document.getElementById('street').options.length;
for(i=0;i<count;i++) {
document.getElementById('street').remove(0);
}
}
//-->
</script>
<select name=district onchange="showStreet(this)">
<option>==请选择==
<option>王芸
<option>李冬
</select>
<select name=street id="street">
</select>
</body>
</html>
给后面name为street的那个设一个ID为street然后通过document.getElementById('street')来取得这个select对象
你的写法一点都不符合W3C标准.所以以后一定要写符合W3C标准的.这样火狐就不会出问题了.下面是我给你写的你看看
<!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>无标题文档</title>
</head>
<body>
<script language="JavaScript">
<!--
var street = new Array(new Array("Authorware多媒体课件制作", "Authorwar游戏开发"),
new Array("flash网站制作", "flash小游戏制作"));
function showStreet(blah) {
removeAll();
index = blah.selectedIndex - 1;
for(i=0;i<street[index].length;i++) {
document.getElementById('street').options.add(new Option(street[index][i]));
}
}
function removeAll() {
count = document.getElementById('street').options.length;
for(i=0;i<count;i++) {
document.getElementById('street').remove(0);
}
}
//-->
</script>
<select name=district onchange="showStreet(this)">
<option>==请选择==
<option>王芸
<option>李冬
</select>
<select name=street id="street">
</select>
</body>
</html>
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询