EasyUI:年份、月份下拉框Demo


EasyUI:年份、月份下拉框Demo

jsp中定義:

<td width="10%" height="25px" style="text-align:center;"><font style="font-size: 12px;">年度:</font></td>
<td width="15%" height="25px"  style="text-align: left;">
  <input id="yearChoose" name="yearChoose" class="easyui-combobox ui-text" type="text"  value="${yearChoose}" style="width:120px" />
</td>
<td width="10%" height="25px" style="text-align:center;"><font style="font-size: 12px;">月份:</font></td>
<td width="15%" height="25px"  style="text-align: left;">
  <input id="monthChoose" name="monthChoose" class="easyui-combobox ui-text" type="text"  value="${monthChoose}" style="width:120px" />
</td>

js中初始化:

//年度下拉框初始化
$("#yearChoose").combobox({   
valueField:'year',    
textField:'year',  
panelHeight:'auto'
});
var data = [];//創建年度數組
var startYear;//起始年份
var thisYear=new Date().getUTCFullYear();//今年
var endYear=thisYear+1;//結束年份
//數組添加值(2012-2016)//根據情況自己修改
for(startYear=endYear-4;startYear<=thisYear;startYear++){ 
  data.push({"year":startYear});
}
$("#yearChoose").combobox("loadData", data);//下拉框加載數據
$("#yearChoose").combobox("setValue",thisYear);//設置默認值為今年
//月度下拉框初始化
$("#monthChoose").combobox({
valueField:'month',    
textField:'month',  
panelHeight:'auto',
editable:false
});
var data1 = [];//創建月份數組
var startMonth=1;//起始月份
var thisMonth=new Date().getUTCMonth()+1;//本月
//數組添加值(1-12月)為固定值
for(startMonth;startMonth<13;startMonth++){
  data1.push({"month":startMonth});
}
$("#monthChoose").combobox("loadData", data1);//下拉框加載數據
$("#monthChoose").combobox("setValue",thisMonth);//設置默認值為本月

效果(年份):

效果(月份):

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM