Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/60.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 逐字删除_Javascript - Fatal编程技术网

Javascript 逐字删除

Javascript 逐字删除,javascript,Javascript,我有个问题。我正在为自己写博客,一切都很顺利。但现在我想对登录输入做些很酷的事情,所以如果我可以一个接一个地删除占位符字符呢 var run = 0; var inte; function removet(obj) { run = 0; setInterval(function () { if(run > 8) { clearInterval(); } else { stri =

我有个问题。我正在为自己写博客,一切都很顺利。但现在我想对登录输入做些很酷的事情,所以如果我可以一个接一个地删除占位符字符呢

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>

登录

删除用户名很好,但当我尝试使用密码时。。。这两个被删除了一半。为什么?我的错误在哪里?

尝试不清除所有间隔

function removet(obj) {
    run = 0;
    var k= setInterval(function () {
        if(run > 8) {
            clearInterval(k);
        }
        else {
            stri = obj.placeholder;
            stri = stri.substring(0, stri.length - 1);
            obj.placeholder = stri;
            run++;
        }
    }, 22, obj);
}

@蒂姆:我也在想同样的事情,但脑子里的描述不太清楚。回答吧!