如何指定在 HTML 載入頁面時預先選擇一個選項?


使用 selected 屬性指定在 HTML 載入頁面時預先選擇一個選項。你可以嘗試執行以下程式碼來實現 selected 屬性 −

示例

<!DOCTYPE html>
<html>
   <head>
      <title>HTML selected attribute</title>
   </head>
   <body>
      <p>Here's the list of subjects. Select any one:</p>
      <form>
         <select name = "dropdown">
            <option value = "Computer Architecture" selected>Computer Architecture</option>
            <option value = "Java">Java</option>
            <option value = "Discrete Mathematics">Discrete Mathematics</option>
         </select>
      </form>
   </body>
</html>

更新於: 2020-03-03

95 次瀏覽

開啟你的 職業生涯

透過完成課程獲得認證

開始
廣告
© . All rights reserved.