js判断阻止表单提交实例
var isnull = document.getElementById("textfield2").value;
var fc = document.getElementById("textfield2");
value = isnull.replace(/\s/g,"");//这里是去掉空字符
if(value == ""){
alert("标题不能为空");
fc.focus();
return false;
}
form1.submit();
}
function vali(){
var isnull = document.getElementById("textfield2").value;
var fc = document.getElementById("textfield2");
value = isnull.replace(/\s/g,"");//这里是去掉空字符
if(value == "")
alert("标题不能为空");
return false;
fc.focus();
}
<form action="<%=basePath%>/hyzx/savaMsg!sendMsg.action" οnsubmit="return vali()" name="form1" method="post">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td height="35" colspan="2" bgcolor="#f7f7f7" class="jn1">发送短消息</td>
</tr>
<tr>
<td width="22%" height="40" align="right" style="padding-top:20px;">标题:</td>
<td width="78%" height="40" align="left" style="padding-top:20px;"><input type="text" name="tbmsg.title" id="textfield2" class="inps" style="width:300px;"/></td>
</tr>
<tr>
<td height="40" align="right">内容:</td>
<td height="40"><textarea name="tbmsg.context" οnclick="vali()" id="textarea" cols="45" rows="5" style="border:1px solid #d2d5db; width:420px; height:140px; padding:5px; font-size:12px;"></textarea></td>
</tr>
<tr>
<td height="90" align="right"> </td>
<td height="90"><a href="javascript:void(0)" οnclick="tijiao()" class="am1">发送短消息</a></td>
</tr>
</table>
</form>