如何在页面加载时指定一个选项在 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>
广告