急!函数错误!

renaski 2003-10-15 10:39:22
以前帖子的内容,可惜我找不到了。
function setFirst(S){
S.First.options[0].value="a";
S.First.options[0].text="a";


S.First.options[1].value="b";
S.First.options[1].text="b";


S.First.options[2].value="c";
S.First.options[2].text="c";

S.First.options[3].value="无";
S.First.options[3].text="**请选择省份**";
S.First.options[3].selected=true;
S.First.length=4;

}
请问这个函数那里有错啊?
输出的时候默认的select里没有东西。
-------------------------------------------------------------
原来的代码
<SCRIPT language=JavaScript>
function setFirst(S){
S.First.options[0].value="a";
S.First.options[0].text="a";


S.First.options[1].value="b";
S.First.options[1].text="b";


S.First.options[2].value="c";
S.First.options[2].text="c";

S.First.options[3].value="无";
S.First.options[3].text="**请选择省份**";
S.First.options[3].selected=true;
S.First.length=4;

}

function setsecond(D){
var valueFirst=D.First.options[D.First.selectedIndex].value;
if(valueFirst.indexOf("无")==0)
{
D.second.length=1;D.second.options[0].value="无";
D.second.options[0].text="**请选择城市**"
D.second.options[0].selected=true;
}

else if(valueFirst.indexOf("a")==0)
{
D.second.length=3;

D.second.options[0].value="abuse";
D.second.options[0].text="abuse";

D.second.options[1].value="abandon";
D.second.options[1].text="abandon";

D.second.options[2].value="acuse";
D.second.options[2].text="acuse";

}

else if(valueFirst.indexOf("b")==0)
{
D.second.length=3;

D.second.options[0].value="bee";
D.second.options[0].text="bee";

D.second.options[1].value="bad";
D.second.options[1].text="bad";

D.second.options[2].value="born";
D.second.options[2].text="born";

}

else if(valueFirst.indexOf("c")==0)
{
D.second.length=3;

D.second.options[0].value="city";
D.second.options[0].text="city";

D.second.options[1].value="capity";
D.second.options[1].text="capity";

D.second.options[2].value="car";
D.second.options[2].text="car";

}

}
</script>


<body onload=setFirst(document.select);setsecond(document.select)>
<Form name="select" method="POST" action="xxx.asp">
<center>
<Table>
<TR> <td>请选择:</td>
<TD ><SELECT onchange=setsecond(document.select) name=First size="1" ></SELECT> <SELECT name=second size="1" ></SELECT> </TD>
</TR>
</Table></center>
</Form>
...全文
19 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
renaski 2003-10-15
  • 打赏
  • 举报
回复
.
孟子E章 2003-10-15
  • 打赏
  • 举报
回复
<SCRIPT language=JavaScript>
function setFirst(S){
S.First.length=4;
S.First.options[0].value="a";
S.First.options[0].text="a";


S.First.options[1].value="b";
S.First.options[1].text="b";


S.First.options[2].value="c";
S.First.options[2].text="c";

S.First.options[3].value="无";
S.First.options[3].text="**请选择省份**";
S.First.options[3].selected=true;


}

function setsecond(D){
var valueFirst=D.First.options[D.First.selectedIndex].value;
if(valueFirst.indexOf("无")==0)
{
D.second.length=1;D.second.options[0].value="无";
D.second.options[0].text="**请选择城市**"
D.second.options[0].selected=true;
}

else if(valueFirst.indexOf("a")==0)
{
D.second.length=3;

D.second.options[0].value="abuse";
D.second.options[0].text="abuse";

D.second.options[1].value="abandon";
D.second.options[1].text="abandon";

D.second.options[2].value="acuse";
D.second.options[2].text="acuse";

}

else if(valueFirst.indexOf("b")==0)
{
D.second.length=3;

D.second.options[0].value="bee";
D.second.options[0].text="bee";

D.second.options[1].value="bad";
D.second.options[1].text="bad";

D.second.options[2].value="born";
D.second.options[2].text="born";

}

else if(valueFirst.indexOf("c")==0)
{
D.second.length=3;

D.second.options[0].value="city";
D.second.options[0].text="city";

D.second.options[1].value="capity";
D.second.options[1].text="capity";

D.second.options[2].value="car";
D.second.options[2].text="car";

}

}
</script>


<body onload=setFirst(document.select);setsecond(document.select)>
<Form name="select" method="POST" action="xxx.asp">
<center>
<Table>
<TR> <td>请选择:</td>
<TD ><SELECT onchange=setsecond(document.select) name=First size="1" ></SELECT> <SELECT name=second size="1" ></SELECT> </TD>
</TR>
</Table></center>
</Form>
孟子E章 2003-10-15
  • 打赏
  • 举报
回复
function setFirst(S){
S.First.length=4;
S.First.options[0].value="a";
S.First.options[0].text="a";


S.First.options[1].value="b";
S.First.options[1].text="b";


S.First.options[2].value="c";
S.First.options[2].text="c";

S.First.options[3].value="无";
S.First.options[3].text="**请选择省份**";
S.First.options[3].selected=true;

87,901

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 JavaScript
社区管理员
  • JavaScript
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧