JS中数组或字符串的截取问题。。

有这样一道题:
一个文本框,用户输入若干关键字,关键字用空格或者逗号隔开。
输入完成后,点击button按钮,使用select控件显示用户输入的每
一个关键字。

没看懂啥意思,难道意思是把文本框里的值传入select下拉框的每一项???不懂啊!!
求本题完整代码。。
最新回答
长青诗

2024-11-29 09:00:37

<script type="text/javascript">
function test(){
the1=document.getElementById("1");
theArray=the1.value.split(",");
the2=document.getElementById("2");
the2.options.length=0;
for(i=0;i<theArray.length;i++){
the2.options.add(new Option(theArray[i]));
}
}
</script>
<input id="1" type="text" />
<input type="button" onclick="test()" value="提交" />
<br />
<select id="2"></select>
繁花晕染

2024-11-29 08:21:58

用split(';')把用户输入解析成数组,然后用来填入select标签
追问
我也知道是这样,但是具体代码怎么实现?谢谢