本文介绍js判断值是否为空的几种方法。
<input type="text" id="name" value=“点击” onclick="checkNull()"/>
方法一:
<script>
function checkNull(){
var name = document.getElementById("name").value.replace(/[]/g,"");//把所有空格去掉
if(name.length==0||name=="点击"){
alert("请输入数据!");
}
}
</script>
方法二:
var a = "";
if (a =="" ||undefined || null) {
alert("数据为空");
}else{
alert("数据正确");
};
声明:如需转载,请注明来源于www.webym.net并保留原文链接:http://www.webym.net/jiaocheng/916.html





















