我遇到了一个问题。我正在为自己制作一个博客,一切都很顺利。但有一天我想用我的登录输入框做点酷炫的事情,那么如果我能够逐个删除占位字符会怎样呢?
var run = 0;
var inte;
function removet(obj) {
run = 0;
setInterval(function () {
if(run > 8) {
clearInterval();
}
else {
stri = obj.placeholder;
stri = stri.substring(0, stri.length - 1);
obj.placeholder = stri;
run++;
}
}, 22, obj);
}
嗨,它能工作了!但是我遇到了一个小问题。这是我的HTML代码:
<input type="text" placeholder="Username" onblur="this.placeholder = 'Username'" onfocus="removet(this)">
<input type="password" placeholder="Password" onblur="this.placeholder = 'Password'" onfocus="removet(this)">
<button type="submit" id="login-button">Login</button>
删除用户名的操作正常,但是当我尝试删除密码时……两者都只删除了一半。为什么?我的错误在哪里?