dropdownlist绑定日期,用Jquery检测起始日期,终止日期合法性

有4个dropdownlist分别是起始年,起始月,终止年,终止月

由于项目要示年的dropdownlist只需绑定当年前的前三年后两年如,2005,2006......

月的dropdownlist绑定1-12

 

下面是实现代码

$(function() { $('#ddlYearEnd').change(function() { var endYear = $(this).val(); var beginYear = $('#ddlYear').val(); if (parseFloat(endYear) < parseFloat(beginYear)) { $(this).val(beginYear); alert('起始年不可大于终止年!'); } var endMonth = $('#ddlMonthEnd').val(); var beginMonth = $('#ddlMonth').val(); if (parseFloat(endYear) == parseFloat(beginYear)) if (parseFloat(endMonth) < parseFloat(beginMonth)) { $('#ddlMonthEnd').val(beginMonth); alert('起始月不可大于终止月!'); } }) $('#ddlYear').change(function() { var endYear = $('#ddlYearEnd').val(); var beginYear = $(this).val(); if (parseFloat(endYear) < parseFloat(beginYear)) { $(this).val(endYear); alert('起始年不可大于终止年!'); } var endMonth = $('#ddlMonthEnd').val(); var beginMonth = $('#ddlMonth').val(); if (parseFloat(endYear) == parseFloat(beginYear)) if (parseFloat(endMonth) < parseFloat(beginMonth)) { $('#ddlMonth').val(endMonth); alert('起始月不可大于终止月!'); } }) $('#ddlMonthEnd').change(function() { var beginYear = $('#ddlYear').val(); var endYear = $('#ddlYearEnd').val(); var endMonth = $(this).val(); var beginMonth = $('#ddlMonth').val(); if (parseFloat(endYear) == parseFloat(beginYear)) if (parseFloat(endMonth) < parseFloat(beginMonth)) { $(this).val(beginMonth); alert('起始月不可大于终止月!'); } }) $('#ddlMonth').change(function() { var beginYear = $('#ddlYear').val(); var endYear = $('#ddlYearEnd').val(); var endMonth = $('#ddlMonthEnd').val(); var beginMonth = $(this).val(); if (parseFloat(endYear) == parseFloat(beginYear)) if (parseFloat(endMonth) < parseFloat(beginMonth)) { $(this).val(endMonth); alert('起始月不可大于终止月!'); } }) })

你可能感兴趣的:(jquery,function)