HTML5 的 <datalist> 元素为 <input> 元素指定了一个预定义的列表选项,实现类似自动完成的效果。
01 |
<!DOCTYPE html> |
02 |
< html > |
03 |
< body > |
04 |
05 |
< form action = "login.php" method = "post" > |
06 |
User: |
07 |
< input list = "username" name = "username" /> |
08 |
< datalist id = "username" > |
09 |
< option value = "Zhlmmc" > |
10 |
< option value = "oschina" > |
11 |
< option value = "Winter Lau" > |
12 |
< option value = "Eddie" > |
13 |
< option value = "Valentin" > |
14 |
</ datalist > |
15 |
Password: |
16 |
< input type = "password" /> |
17 |
< input type = "submit" value = "Login" /> |
18 |
</ form > |
19 |
20 |
</ body > |
21 |
</ html > |
<datalist> 标签当前只是 Firefox 和 Opera 浏览器支持,希望其他浏览器能尽快支持。
<datalist> 最终的运行效果如下:
发表回复