原生input限制内容长度和chrome浏览器等自动填充密码

2019-11-15  本文已影响0人  sssgoEasy

一.采用原生maxlength属性

<input type="text"  maxlength="5" />   //可以

<input type="number"  maxlength="5" />  //没有效果

<input type="number" oninput="if(value.length>5) value=value.slice(0,5)" /> //js控制,可以

<input type="tel"  maxlength="5" />  //tel类型,可以

二.H5新增属性 autocomplete="off"

提示:您可以把表单的 autocomplete 设置为 on,同时把特定的输入字段设置为 off,反之亦然。

三. element

auto-complete="new-password"

上一篇下一篇

猜你喜欢

热点阅读