Loading...

javascript如何通過其 ID 設置選擇元素的選定選項?

Temperature: 0 °C

Mark ChangMark Chang
author_tools

如題,透過javascript來針對某個select的option來做選定。

document.getElementById("要用來設置select的ID").selectedIndex=第幾個option;

或者
document.getElementById("要用來設置select的ID").options.namedItem("第幾個option").selected=true;

或者
document.getElementById("要用來設置select的ID").options[第幾個option].selected=true;

以上紀錄~
 

#故事  #javascript  #select  #option  
https://innstory.com/story-javascript如何通過其_ID_設置選擇元素的選定選項-3144
javascript

Prev
 使用PHP資料量太大遇到Allowed_memory_size_of_134217728_bytes_exhausted_問題

Next
使用PHP取得指定月份最後一天的日期 

About the Author

Mark Chang

離不開電腦的宅男

Visitor message

Leave some footprints to prove that you visited me

Recommended reading

Author's other related stories

javascript獲取當前時間

javascript獲取當前...

watchclock var myDate = new Date(); //獲取當前年 var ye...

Format JavaScript Date to yyyy-mm-dd

Format JavaScr...

timecalendar5 JavaScript將Sun May ,轉換成yyyymmdd func...

Fatal error: Allowed memory size of 50331648 bytes exhausted (tried to allocate 12288 bytes) in

Fatal error: A...

今天在客戶的網站系統上發現了一個問題。 在上傳檔案時發生了一個錯誤: Fatal error: Al...

Please select an option

error

Hi, thank you for your participation, but you cannot vote repeatedly~

Join innstory now and start recording your story.

"Innstory" is a place to store stories. We are committed to becoming a warm platform. Deepening the bonds between people is our direction.
We are convinced that the blockchain between people is not just a cold calculation. Join us now.

Wrong format