首页 文章资讯内容详情

如何禁用HTML输入字段的自动完成功能?

2026-06-04 1 花语

<!DOCTYPE html> <html> <head> <style> input{ font-size: 18px; padding: 10px; margin: 10px; border:1px solid grey; } </style> </head> <body> <h1>Autocomplete on/off Example</h1> <form> First name: <input type="text" name="firstName" autocomplete="off"><br> Last name: <input type="text" name="lastName" autocomplete="on"><br> <input type="submit"> </form> <h2>键入以上字段并刷新页面以查看工作中的自动完成</h2> </body> </html>

输出结果

上面的代码将产生以下输出-

提交表单一次后在上述字段中键入内容-