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

PHP重新排列陣列中的元素shuffle()函數

PHP重新排列陣列中的元素s...

shuffle() 是可以將陣列中元素的順序重新洗牌的函數。 甚麼時候用的到? 例如最近寫著一個抽獎...

在PHP裡添加HTTP Strict Transport Security

在PHP裡添加HTTP St...

要通過 PHP 啟用 HTTP 嚴格傳輸安全,請使用以下設定。 <?php //告訴瀏覽器站點只能通...

使用jquery判斷上傳檔案大小

使用jquery判斷上傳檔案...

首先得引用jquery var fileSize = document.getElementById...

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