HTML使用JavaScript禁止浏览器自动填写用户名密码

2021-09-16 01:25286

HTML使用JavaScript禁止浏览器自动填写用户名密码

HTML:

<div class="form-floating mb-3">
	<input type="tel" name="username" class="form-control" id="username" placeholder="手机号" readonly="readonly">
	<label for="floatingInput">手机号</label>
</div>
<div class="form-floating mb-3">
	<input type="password" name="password" class="form-control" id="password" placeholder="设置密码" readonly="readonly">
	<label for="floatingPassword">设置密码</label>
</div>


JavaScript:

<script>
    setTimeout(function removeReadonly(){ 
        var username=document.getElementById("username");
        var password=document.getElementById("password");
        username.removeAttribute("readonly");
        password.removeAttribute("readonly");
    },1000);
</script>


QQ截图20210629013731.png