为什么这个onblur不起作用

    //占位符点击消失
    <input type="text" id="text" value="请输入一个数字">
    -----------------------------------
    var input_txt = document.getElementById("text");
    function clicknone() {
        if( input_txt.value == "请输入一个数字" ) {
            input_txt.value = "";
        }

        if( input_txt.value == ""){
            input_txt.value = "请输入一个数字";
        }
    }
    //获得焦点
    input_txt.onfocus = function(){
        clicknone();
    }
    //失去焦点
    input_txt.onblur = function() {
        clicknone();
    }
    
阅读 5.1k
3 个回答

你可以用input的placeholder属性

第二个if判断,写成双等号了。

不能只判断是不是为空 有可能是null 或者undefined呢

推荐问题