欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

JQuery驗證jsp頁面屬性是否為空(實例代碼)

 更新時間:2013年11月08日 09:23:26   作者:  
JQuery驗證jsp頁面屬性是否為空的實例代碼。需要的朋友可以過來參考下,希望對大家有所幫助

說明:驗證是否為空的前提首先要保證是在提交form之前驗證的,如果驗證結(jié)果有為空的項那么限制表單不能提交,并且提示驗證錯誤信息,驗證頁面屬性都不為空的情況下表單正常提交,這部分屬于JS部分的東西,與后臺業(yè)務(wù)邏輯層和控制層基本沒有任何關(guān)系。

限制提交的方法可以是在form標簽里限制,也可以是在submit按鈕上添加onclick事件限制:

<form action=".." method="post" onsubmit="return check();">
<input type="submit" value="提交" onclick="return check()" >

案例:

復制代碼 代碼如下:

<form action="./login.action" method="post" onsubmit="return check();">
<table>
<tr>
<td width="451">&nbsp;</td>
<td width="378">

<table >
<tr>
<td width="60">&nbsp;</td>
<td>
<font color="#000000">用戶名:</font>
</td>
<td align="left"> <input name="userInfo.userName" id="userName" type="text">
<span id="checkUserName"></span>
</td>
<tr> <td>&nbsp;</td>
<td align="right" nowrap>
<font color="#000000">密 碼:</font>
</td>
<td align="left">
<input name="userInfo.password" id="password" type="password">
<span id="checkPassword"></span>
</td>
</tr>
<tr>
<td colspan="4" align="center" nowrap>
<input type="submit" id="btnLog" value=" 登 錄 " >
&nbsp;&nbsp; <input type="reset" value=" 重 置 ">
</td>
</tr>
</table>
</form>


<!--引入js文件 jquery-->
復制代碼 代碼如下:

<script type="text/javascript" src="js/common/jquery-1.5.1.min.js"></script>

<script type="text/javascript">
function check(){
var userName=$("#userName").val();
var password=$("#password").val();
alert(userName);
alert(password);
if(userName==""){
$("#checkUserName").html("<font color='red'>用戶名不能為空!</font>");
return false;
}
if(password==""){
$("#checkPassword").html("<font color='red'>密碼不能為空!</font>");
return false;
}
return true;
}
</script>

相關(guān)文章

最新評論