表單中下拉列表的傳值

select傳值的兩種方式
第一種:直接在html中修改就能夠
<select onchange="obtain(this.options[this.options.selectedIndex.text]")>
<option value="1">internet explore</option>
<option value="2">opera</option>
<option value="3">google</option>
</select>
您選擇的瀏覽器是:<input type="text" value="" id="browser">
<script>
function obtain(obj){
document.getElementById("browser").value=obj;
}
</script>
第二種方式
<p>請選擇您喜歡的瀏覽器:html

<select name="" id="selectList" onchange="obtain()">
        <option value="1">internet explore</option>
        <option value="2">opera</option>
        <option value="3">google</option>
    </select>

您選擇的瀏覽器是:<input type="text" value="" id="browser">
</p>
<script>
function obtain(){
let mylist=document.getElementById("selectList");
document.getElementById("browser").value=mylist.options[mylist.selectedIndex].text;
}
</script>瀏覽器

相關文章
相關標籤/搜索