我对Jquery“ datapicker”和Jquery“ validation”有问题。我有两个textfeilds具有dropdow datepicker日历,如果在提交时选择了日期,则它们的背景色为“红色”。 如果随后选择了日期,则背景颜色保持“红色”,表示背景未清除。谁能看到原因或向我指出正确的方向。
Jquery代码:
$(document).ready(function() {
$('#RoomToDate2').change(function() {
var fromdate = $('#RoomFromDate2').val();
var todate = $('#RoomToDate2').val();
var newfromdate = fromdate.split("-").reverse().join("-");
var newtodate = todate.split("-").reverse().join("-");
if(newtodate < newfromdate){
$.alert({
type: 'red',
title: 'Error: Dates ',
content: 'The "To" date '+todate+' is less than the "From" date '+fromdate+'.<br/><br/> Adjust your dates.',
animation: 'zoom',
boxWidth: '50%',
closeAnimation: 'zoom',
buttons: {
Close: function() {
text: 'Close'
}
}
})
}
});
});
验证码:
$(function() {
$("#form2").validate({
rules:{
ClientName: {
required: true
},
RoomFromDate: {
required: true
},
RoomToDate: {
required: true
},
RoomFromTimeH: {
required: true
},
RoomToTimeH: {
required: true
},
RoomFromTimeM: {
required: true
},
RoomToTimeM: {
required: true
},
ClientContactEmail: {
required: false
},
},
messages: {
ClientName: {
required: ""
},
RoomFromDate: {
required: ""
},
RoomToDate: {
required: ""
},
RoomFromTimeH: {
required: ""
},
RoomToTimeH: {
required: ""
},
RoomFromTimeM: {
required: ""
},
RoomToTimeM: {
required: ""
},
},
// Called when the element is invalid:
highlight: function(element) {
$(element).css('background', '#ffdddd');
},
// Called when the element is valid:
unhighlight: function(element) {
$(element).css('background', '#ffffff');
}
});
$("#ClientContactEmail").change(function(){
$(this).removeData();
});
});
在此先感谢您的帮助和时间。