首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > Java Web开发 >

使用过jquery validate 的朋友请进帮忙解决个有关问题~

2012-01-12 
使用过jquery validate 的朋友请进帮忙解决个问题~~!!这是我的JS$(#saleLaptopAdd).validate({rules: {

使用过jquery validate 的朋友请进帮忙解决个问题~~!!
这是我的JS
$("#saleLaptopAdd").validate({
rules: {
"loginName":{required: true, email: true},
"saleLaptop.serviceCode":{required: true},
"relationMode":{required: true},
"saleLaptop.title":{required: true},
"brand":{required: true},
"saleLaptop.laptopCPUSeriesId":{required: true},
"saleLaptop.cpuCoreTotal":{required: true},
"saleLaptop.monitorSizeId":{required: true},
"saleLaptop.ramSizeId":{required: true},
"saleLaptop.hddSizeId":{required: true},
"saleLaptop.vgaTypeId":{required: true},
"saleLaptop.romTypeId":{required: true},
"saleLaptop.colorId":{required: true},
"saleLaptop.usbTotalId":{required: true},
"saleLaptop.depreciationGrade":{required: true},
"saleLaptop.goodsTotal":{required: true, digits: true},
"saleLaptop.price":{number: true}
},
messages: {
"loginName":{email: "*账户长度或格式不正确"},
"relationMode":{required: "*点击选择联系地址"},
"saleLaptop.title":{required: "*标题未填写"},
"brand":{required: "*请点击选择品牌"},
"saleLaptop.laptopCPUSeriesId":{required: "*必选项"},
"saleLaptop.cpuCoreTotal":{required: "*必选项"},
"saleLaptop.monitorSizeId":{required: "*必选项"},
"saleLaptop.ramSizeId":{required: "*必选项"},
"saleLaptop.hddSizeId":{required: "*必选项"},
"saleLaptop.vgaTypeId":{required: "*必选项"},
"saleLaptop.romTypeId":{required: "*必选项"},
"saleLaptop.colorId":{required: "*必选项"},
"saleLaptop.usbTotalId":{required: "*必选项"},
"saleLaptop.depreciationGrade":{required: "*必选项"},
"saleLaptop.goodsTotal":{digits: "*只能输入整数"},
"saleLaptop.price":{number: "*请输入合法的价格"}
}
}); 


-------------------------------------------
这是下面的form 代码

<form id="saleLaptopAdd" action="" method="post" style="padding-left:36%;">
<input id="filePathStr" type="hidden" value=""> <!--用于保存需要的文件路径 -->
<table border="0" >
<tr>
<td>是否商家用户:</td>
<td>
<input type="radio" name="saleLaptop.isEnterprise" value="1" checked="checked" onclick="isEnterpriseClick('toCity');"/>是
<input type="radio" name="saleLaptop.isEnterprise" value="0" onclick="javascript:$('#isStudent').show();"/>否
</td>
</tr>
<tr id="isStudent" style="display: none;">
<td>学生用户:</td>
<td>
<input id="isStudentInput" type="checkbox" value="1" onclick="isStudentChose(this,'toCity');"/>是
</td>
</tr>
<tr>
<td>帐号:</td>
<td>
<input type="text" id="loginName" name="loginName" onblur="v_nameAndCodeOnBlur(this, 'serviceCode');" onkeydown="nameAndCodeOnChange();"/>
<input type="hidden" id="commonUserId" name="saleLaptop.commonUserId"/>
</td>
</tr>
<tr>
<td>服务码:</td>
<td>
<input type="text" id="serviceCode" name="saleLaptop.serviceCode" onblur="v_nameAndCodeOnBlur(this, 'loginName');" onkeydown="nameAndCodeOnChange();"/>


<div id="nameCodeErrorHint" style="display:none;font-size:12px;color:red;"> 用户名和服务码不匹配</div>
</td>
</tr> 
<tr>
<td>联系方式:</td>
<td>
<input type="text" id="relationMode" name="relationMode" onfocus="javascript:if(hasValidate==true)$('#communicationContainer').show();" readonly="readonly" style="width: 250px;"/>
<input type="hidden" id="commonUserCommunicationId" name="saleLaptop.commonUserCommunicationId" />
</td>
</tr>

<tr>
<td>信息标题:</td>
<td>
<input type="text" name="saleLaptop.title" size="32"/>
</td>
</tr>
<tr>
<td>上传图片:</td>
<td>
<div id="browseBtn"><input type="file" name="fileupload" id="fileupload" /></div>
<div id="fileQueue"></div>
<p style="display: none;">
<a href="javascript:;" onClick="javascript:uploadifyUpload()">开始上传</a>&nbsp;
<a href="javascript:jQuery('#fileupload').uploadifyClearQueue()">取消所有上传</a>
</p>
<div class=files style="margin-left: 0px; background-color: #F0F8FF;"></div>
</td>
</tr>
<tr>
<td>主机品牌:</td>
<td>
<input id="brand" name="brand" type="text" size="20" value="" readonly="readonly" onclick="javascript:$('#brandDiv').show();">
</td>
</tr>
<tr>
<td colspan="2">
<div id="brandDiv" style="display: none;border: 1px solid black;background-color: white">
<table>
<tr>
<td colspan="3" align="left"><a href="#" onclick="javascript:$('#brandDiv').hide();">关闭</a></td>
</tr>
<c:set var="i" value="0" />
<c:forEach var="myBrandList" items="${myBrandList}" varStatus="status">
<c:if test="${status.index%3==0}">
<tr>
</c:if>
<c:set var="i" value="${i+1}" />
<td><input id="brandRadio_${myBrandList.id}" type="radio" name="saleLaptop.brandId" value="${myBrandList.id}" onclick="choseBrand(this);"><span id="brand_${myBrandList.id}"><label for="brandRadio_${myBrandList.id}">${myBrandList.brandName}</label></span></td>
<c:if test="${i%3==0}"> <%--控制一行输出多少个 --%>
</tr>
<c:set var="i" value="0"></c:set>
</c:if>
</c:forEach>
</table>
</div>
</td>
</tr>
<tr>
<td>CPU系列:</td>
<td>
<select name="saleLaptop.laptopCPUSeriesId">
<option value=""></option>
<c:forEach var="myCpuSeriesList" items="${myCpuSeriesList}">
<option value="${myCpuSeriesList.id}">${myCpuSeriesList.named}</option>
</c:forEach>
</select>
</td>
</tr>
<tr>
<td>CPU型号:</td>
<td>
<input type="text" name="saleLaptop.cpuType"> 


</td>
</tr>
<tr>
<td>CPU核心数:</td>
<td>
<select name="saleLaptop.cpuCoreTotal">
<option value=""></option>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
<option value="6">6</option>
<option value="7">7</option>
<option value="8">8</option>
<option value="9">9</option>
<option value="10">10</option>
</select> 
</td>
</tr>
<tr>
<td>处理器主频:</td>
<td>
<input id="cpuClockSpeed" type="text" name="saleLaptop.cpuClockSpeed">GHz
</td>
</tr>
<tr>
<td>是否宽屏:</td>
<td>
<input id="isWideMonitor" type="radio" name="saleLaptop.isWideMonitor" checked="checked">是
<input id="isWideMonitor" type="radio" name="saleLaptop.isWideMonitor">否
</td>
</tr>
<tr>
<td>屏幕尺寸:</td>
<td>
<select name="saleLaptop.monitorSizeId">
<option value=""></option>
<c:forEach var="myMonitorSizeList" items="${myMonitorSizeList}">
<option value="${myMonitorSizeList.id}">${myMonitorSizeList.named}</option>
</c:forEach>
</select>
</td>
</tr>
<tr>
<td>内存大小:</td>
<td>
<select name="saleLaptop.ramSizeId">
<option value=""></option>
<c:forEach var="myRamSizeList" items="${myRamSizeList}">
<option value="${myRamSizeList.id}">${myRamSizeList.size}</option>
</c:forEach>
</select>
</td>
</tr>
<tr>
<td>硬盘容量:</td>
<td>
<select name="saleLaptop.hddSizeId">
<option value=""></option>
<c:forEach var="myHddSizeList" items="${myHddSizeList}">
<option value="${myHddSizeList.id}">${myHddSizeList.size}</option>
</c:forEach>
</select>
</td>
</tr>
<tr>
<td>显卡类型:</td>
<td>
<select name="saleLaptop.vgaTypeId" >
<option value=""></option>
<c:forEach var="myVgaTypeList" items="${myVgaTypeList}">
<option value="${myVgaTypeList.id}">${myVgaTypeList.types}</option>
</c:forEach>
</select>
</td>
</tr>
<tr>
<td>显卡芯片型号:</td>
<td>
<input type="text" name="saleLaptop.vgaChipType" />
</td>
</tr>
<tr>
<td>光驱类型:</td>
<td>
<select name="saleLaptop.romTypeId">
<option value=""></option>
<c:forEach var="myRomTypeList" items="${myRomTypeList}">
<option value="${myRomTypeList.id}">${myRomTypeList.types}</option>
</c:forEach>
</select>


</td>
</tr>
<tr>
<td>笔记本颜色:</td>
<td>
<select name="saleLaptop.colorId">
<option value=""></option>
<c:forEach var="myColorList" items="${myColorList}">
<option value="${myColorList.id}">${myColorList.colorName}</option>
</c:forEach>
</select>
</td>
</tr>
<tr>
<td>USB接口个数:</td>
<td>
<select name="saleLaptop.usbTotalId">
<option value=""></option>
<option value="2">2个</option>
<option value="3">3个</option>
<option value="4">4个</option>
<option value="5">5个</option>
<option value="6">6个及以上</option>
</select>
</td>
</tr>

<tr align="center">
<td colspan="2" >
<span style="margin-right:50px;"><input type="submit" value="提交"/></span>
<input type="reset" value="重置" onclick="return confirm('重置将会清空您已填写的所有信息,确定重置吗?');"/>
 </td>
</tr>
</table>
</form>
-------------------------------------------------

奇怪的结果是,文本域可以进行实时验证,也就是 鼠标一离开就进行验证,但是,select下拉列表却不可以。只有点击提交后才会验证显示出来错误提示,并且,当我将下拉列表选择上一个以后,已经正确选择了,它那个错误提示还在,为什么啊??? 
可是简单的input文本域是可以实时地验证的啊。
为什么select下拉列表就不可以呢?
我的问题出现在哪??
帖子过长,所以删掉了部分FORM里的代码,都一样的。

[解决办法]

探讨
引用:
版本?你用的validate什么版本,这个我也用的,好用是好用,就是比较万恶的是它默认在元素的后面现实验证消息,有的时候会破坏页面格式.还不知道如何去修改.


恩,是版本问题 1.5的有问题,1.6就没有那个问题。
默认验证消息确实是在后面提示,正常尝试读源码解决中。。。。。

热点排行