2017 年 9 月 27 日 js(文本框内容添加到select)

写法

<!DOCTYPE html>
<html>
    <head>
        <meta charset="UTF-8">
        <title></title>
        <style>
            #sy{
                 300px;
            }
        </style>
    </head>
    <body>
            <select id="sy"    size="7">
                
            </select>
            <input type="text" id="tx1"/>
            <input type="button" id="s1" value="提交" />
    </body>
</html>
<script>
    var tx1 = document.getElementById("tx1")
    var s1 = document.getElementById("s1")
    var sy = document.getElementById("sy")
    s1.onclick = function(){
        sy.innerHTML += "<option>"+ tx1.value+"</option>"
        tx1.value = ""
    }
</script>

原文地址:https://www.cnblogs.com/zJuevers/p/7601651.html