怎么判断为空 <input type="text" /><input type="text" /><input type="submit" value="提交" />请问下 怎么文本框判断为空 当文本框为空的时候 按提交按钮弹窗 提交失败 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 <script type="text/javascript"> function check(f) { if (f.txt1.value == "") { alert('txt1不能为空!'); f.txt1.focus(); return false; } if (f.txt2.value == "") { alert('txt2不能为空!'); f.txt2.focus(); return false; } }</script></head><form onsubmit="return check(this)"><input type="text" name="txt1" /><input type="text" name="txt2" /><input type="submit" value="提交" /></form> <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script><script type="text/javascript"> $(function(){ $(":submit").click(function(){ $("input[type=text]").each(function(i,j){ if($(this).val()==""){ alert("第"+(parseInt(i)+1)+"个文本框为空提交失败"); return false; } }); }); })</script> if (文本框id.value == "") { alert('不能为空!');} var txtValue = document.getElementById("txt").value;txtValue = txtValue.replace(/^ /, "").replace(/ $/, ""); // 去除字符串起始空格和尾部空格txtValue = txtValue.replace(/ /, ""); // 替换全角空格if (txtValue.length == 0) { return false; // 内容为空 }return true;// 另一种JQUERY写法更方便var txtValue = $("#txt").val();if ($.trim(txtValue).length == 0) { return false;}return true; var str = $.trim($("#txt").val());获取值后去空格判断是否为:“”if(str == ""){ return false;} web Browser 打印问题 验证手机号码JS 刚才写了一个算法,大家提提意见 不断闪烁的文字+闪烁文字的迁移 效果/求助 用js触发CTRL+F,如何实现? 请问富文本编辑器UEditor怎么解析出来数据库中保存的值呢? 真是奇怪?为什么函数不执行?100分相送 如何对form中的一个文本框reset? 关于日期的提问,高手答对者给分 求教,为什么录制好下载下来的视频长度和在线播放的不一致 jsp上传图片预览的问题 非常怪异的Jquery问题
function check(f) {
if (f.txt1.value == "") { alert('txt1不能为空!'); f.txt1.focus(); return false; }
if (f.txt2.value == "") { alert('txt2不能为空!'); f.txt2.focus(); return false; }
}
</script>
</head>
<form onsubmit="return check(this)">
<input type="text" name="txt1" />
<input type="text" name="txt2" />
<input type="submit" value="提交" /></form>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<script type="text/javascript">
$(function(){
$(":submit").click(function(){
$("input[type=text]").each(function(i,j){
if($(this).val()==""){
alert("第"+(parseInt(i)+1)+"个文本框为空提交失败");
return false;
}
});
});
})
</script>
var txtValue = document.getElementById("txt").value;
txtValue = txtValue.replace(/^ /, "").replace(/ $/, ""); // 去除字符串起始空格和尾部空格
txtValue = txtValue.replace(/ /, ""); // 替换全角空格
if (txtValue.length == 0) { return false; // 内容为空 }
return true;// 另一种JQUERY写法更方便
var txtValue = $("#txt").val();
if ($.trim(txtValue).length == 0) {
return false;
}
return true;
var str = $.trim($("#txt").val());
获取值后去空格判断是否为:“”
if(str == ""){
return false;
}