请教关于javascript验证问题

来源:百度知道 编辑:UC知道 时间:2024/05/31 03:38:42
我想在客户端页面通过JS验证TextBox的输入是否为空,请教各位该js如何写?

设你的TextBox的id="id1",提交表单时调用验证函数 onsubmit="return checktext();"
<script>
function checktext(){
var boxValue=document.getElementById('id1').value;
if(boxValue==""){
alert('TextBox为空');
return false;
}else{
return true;
}
}

</script>