<a href=javascript:addItem("abc")>abc</a>
<a href=javascript:addItem("def")>def</a>
<select name=talkto></select>
<script>
function addItem(str){
with(document.all.talkto){
add(new Option(str,str))
length++
for(i=length-1;i>0;i--){options[i].text=options[i-1].text;options[i].value=options[i-1].value}
options[i].text=str;options[i].value=str
}
}
</script>

解决方案 »

  1.   

    <a href=javascript:addItem("abc")>abc</a>
    <a href=javascript:addItem("def")>def</a>
    <select name=talkto></select>
    <script>
    function addItem(str){
    with(document.all.talkto){
    length++
    for(i=length-1;i>0;i--){options[i].text=options[i-1].text;options[i].value=options[i-1].value}
    options[i].text=str;options[i].value=str
    }
    }
    </script>
      

  2.   

    第二种,修改selectedIndex
    <a href=javascript:addItem("abc")>abc</a>
    <a href=javascript:addItem("def")>def</a>
    <select name=talkto></select>
    <script>
    function addItem(str){
    with(document.all.talkto){
    add(new Option(str,str))
    selectedIndex=length-1
    }
    }
    </script>
      

  3.   

    <a href=javascript:addItem("abc")>abc</a>
    <a href=javascript:addItem("def")>def</a>
    <a href=javascript:addItem("ghi")>ghi</a>
    <select name=talkto></select>
    <script>
    function addItem(str){
    with(document.all.talkto){
    length++
    for(i=length-1;i>0;i--)
    if(options[i-1].text==str)options[i-1].removeNode(true);
    else{options[i].text=options[i-1].text;options[i].value=options[i-1].value}
    options[i].text=str;options[i].value=str
    }
    }
    </script> 
      

  4.   

    我把代码放到框架里就会bug出现.连点一个用户名,下拉菜单会变得看不见
    right.htm
    <html>
    <head>
    <meta name="GENERATOR" content="Microsoft FrontPage 5.0">
    <meta name="ProgId" content="FrontPage.Editor.Document">
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
    <title>abc def ghi</title>
    </head>
    <body>
    <a href=javascript:addItem("abc")>abc</a>
    <a href=javascript:addItem("def")>def</a>
    <a href=javascript:addItem("ghi")>ghi</a>&nbsp;
    <script>
    function addItem(str){
    with(parent.left.document.all.talkto){
    length++
    for(i=length-1;i>0;i--)
    if(options[i-1].text==str)options[i-1].removeNode(true);
    else{options[i].text=options[i-1].text;options[i].value=options[i-1].value}
    options[i].text=str;options[i].value=str
    }
    }
    </script>
    </body>
    </html>
    left.htm
    <html>
    <head>
    <meta name="GENERATOR" content="Microsoft FrontPage 5.0">
    <meta name="ProgId" content="FrontPage.Editor.Document">
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
    <title>新建网页 3</title>
    </head>
    <body>
    <p><select size="1" name="talkto">
    <option>所有人</option>
    </select></p>
    </body>
    </html>