鍍金池/ 問答/HTML5  HTML/ 為什么這個(gè)onblur不起作用

為什么這個(gè)onblur不起作用

    //占位符點(diǎn)擊消失
    <input type="text" id="text" value="請輸入一個(gè)數(shù)字">
    -----------------------------------
    var input_txt = document.getElementById("text");
    function clicknone() {
        if( input_txt.value == "請輸入一個(gè)數(shù)字" ) {
            input_txt.value = "";
        }

        if( input_txt.value == ""){
            input_txt.value = "請輸入一個(gè)數(shù)字";
        }
    }
    //獲得焦點(diǎn)
    input_txt.onfocus = function(){
        clicknone();
    }
    //失去焦點(diǎn)
    input_txt.onblur = function() {
        clicknone();
    }
    
回答
編輯回答
抱緊我

不能只判斷是不是為空 有可能是null 或者undefined呢

2018年5月16日 14:25
編輯回答
莓森

你可以用input的placeholder屬性

2018年4月24日 14:25
編輯回答
心悲涼

第二個(gè)if判斷,寫成雙等號(hào)了。

2018年7月16日 09:06