jQuery插件valiDate验证问题?
就餐时间必须大于当前时间点,分钟也一样。2个下拉框需要同事判断,效果总是出不来。if(nowDate==changeTime){jQuery.validator.addM...
就餐时间必须大于当前时间点,分钟也一样。2个下拉框需要同事判断,效果总是出不来。
if (nowDate == changeTime) {
jQuery.validator.addMethod("isTimeHour", function (value, element) {
var h = value.substring(0, value.length - 1);
alert(h + "------------" + nowTimHour);
return optional(element || h > nowTimHour);
}, "请正确选择就餐时间。");
jQuery.validator.addMethod("isTimeMin", function (value, element) {
var m = value.substring(0, value.length - 1);
alert(m + "------------" + nowTimMin);
return optional(element || m > nowTimMin);
}, "请正确选择就餐时间。");
alert("Ok");
}
else if (nowDate > changeTime) {
alert("选择的日期不正确,请重新选择!");
}
$("#from").validate({
rules: {
selectHour: {
required: true,
isTimeHour: true
},
selectMin: {
required: true,
isTimeMin: true
}
}
messages: {
selectHour: {
required: "请输入正确的就餐时间。",
isTimeHour: "请输入正确的就餐时间。"
},
selectMin: {
required: "请输入正确的就餐时间。",
isTimeMin: "请输入正确的就餐时间。"
}
}
<dt ><span class="base_warning">*</span>就餐时间</dt>
<dd>
<select name="selectHour" id="selectHour" class="isTimeHour" >
<option value="10点">10点</option>
<option value="11点">11点</option>
<option value="12点">12点</option>
<option value="13点">13点</option>
<option value="14点">14点</option>
</select>
<select name="selectMin" id="selectMin" class="isTimeMin" >
<option value="00分">00分</option>
<option value="15分">15分</option>
<option value="30分">30分</option>
<option value="45分">45分</option>
</select>
<div class="onShow">请选择正确就餐时间。</div>
</dd> 展开
if (nowDate == changeTime) {
jQuery.validator.addMethod("isTimeHour", function (value, element) {
var h = value.substring(0, value.length - 1);
alert(h + "------------" + nowTimHour);
return optional(element || h > nowTimHour);
}, "请正确选择就餐时间。");
jQuery.validator.addMethod("isTimeMin", function (value, element) {
var m = value.substring(0, value.length - 1);
alert(m + "------------" + nowTimMin);
return optional(element || m > nowTimMin);
}, "请正确选择就餐时间。");
alert("Ok");
}
else if (nowDate > changeTime) {
alert("选择的日期不正确,请重新选择!");
}
$("#from").validate({
rules: {
selectHour: {
required: true,
isTimeHour: true
},
selectMin: {
required: true,
isTimeMin: true
}
}
messages: {
selectHour: {
required: "请输入正确的就餐时间。",
isTimeHour: "请输入正确的就餐时间。"
},
selectMin: {
required: "请输入正确的就餐时间。",
isTimeMin: "请输入正确的就餐时间。"
}
}
<dt ><span class="base_warning">*</span>就餐时间</dt>
<dd>
<select name="selectHour" id="selectHour" class="isTimeHour" >
<option value="10点">10点</option>
<option value="11点">11点</option>
<option value="12点">12点</option>
<option value="13点">13点</option>
<option value="14点">14点</option>
</select>
<select name="selectMin" id="selectMin" class="isTimeMin" >
<option value="00分">00分</option>
<option value="15分">15分</option>
<option value="30分">30分</option>
<option value="45分">45分</option>
</select>
<div class="onShow">请选择正确就餐时间。</div>
</dd> 展开
1个回答
展开全部
jQuery.validator.addMethod("isTimeHour", function (value, element) {
var h = value.substring(0, 2),nowTimHour = (new Date()).getHours();
return this.optional(element) || (h > nowTimHour);
}, "请正确选择就餐时间。");
jQuery.validator.addMethod("isTimeMin", function (value, element) {
var m = value.substring(0, 2),nowTimMin = (new Date()).getMinutes();
return this.optional(element) || (m > nowTimMin);
}, "请正确选择就餐时间。");
var h = value.substring(0, 2),nowTimHour = (new Date()).getHours();
return this.optional(element) || (h > nowTimHour);
}, "请正确选择就餐时间。");
jQuery.validator.addMethod("isTimeMin", function (value, element) {
var m = value.substring(0, 2),nowTimMin = (new Date()).getMinutes();
return this.optional(element) || (m > nowTimMin);
}, "请正确选择就餐时间。");
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询