簡體   English   中英

我們如何將文本框的值設置為下拉列表?

[英]how can we set textbox value to dropdownlist?

 function SetUtcTimeZone() {
     var UTCTimeZone = document.getElementById("txtPortorAnchorDeparture").value;
     document.getElementById('ddlUTCTimeZone').selectedIndex = UTCTimeZone;
 }

我們如何使用dropdownlist id將textbox值設置為dropdownlist

我想它看起來像這樣:

function SetTxt() {
     var indx = document.getElementById('ddlUTCTimeZone').selectedIndex;
     var val  = document.getElementById('ddlUTCTimeZone').options[indx].text;
     document.getElementById("txtPortorAnchorDeparture").value = val;
}

只需將.selectedIndex替換為.value就可以了
嘗試這個

 function SetUtcTimeZone() { var UTCTimeZone = document.getElementById("txtPortorAnchorDeparture").value; document.getElementById('ddlUTCTimeZone').value = UTCTimeZone; } 
 <!-- Simple example --> <select id="ddlUTCTimeZone"> <option value="1">USA</option> <option value="2">Egypt</option> <option value="0">GMT</option> </select> <input id="txtPortorAnchorDeparture" type="text" /> <button type="button" onclick="SetUtcTimeZone()">Go</button> 

這是一個簡單的功能

function dropdownToTextbox(dropdown, textbox) {
    var selectedOption = dropdown.options[dropdown.selectedIndex];
    textbox.value = selectedOption.value;
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM