<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>js判断输入是否为空</title>
<script type="text/javascript" src="js/jquery.min.js"></script>
</head>
<body>
<div>
<input type="text" id="text" />
<input type="button" id="pan" value="点击" />
</div>
<script>
$(function() {
$("#pan").click(function(){
var txt=$("#text").val();
console.log(txt);
if(!isEmpty(txt)){
alert(txt);
}else{
alert("输入不能为空")
}
});
});
function isEmpty(str) {
if(str === undefined) {
return true;
}
else if(str == null) {
return true;
} else {
var reg = /^\s*$/;
return reg.test(str);
}
}
</script>
</body>
</html>
js判断字符串是否为空字符串
最新推荐文章于 2023-12-20 18:08:58 发布