如何在頁面載入時指定一個選項在 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>

更新於:03-Mar-2020

95 次瀏覽

開啟你的 職業生涯

透過完成課程來獲得認證

開始
廣告