var a =document.getElementById("notValid"); if(!a) {//a为null 或者"" 或者0 alert("javascript 字符串为null、""或者是0"); }