下拉列表显示时间

来源:互联网 发布:位图软件什么意思 编辑:程序博客网 时间:2024/05/20 20:57

整合了下网上资料,弄了个自己的方法,可以参考下:

<%@ page language="java" contentType="text/html; charset=UTF-8"pageEncoding="UTF-8"%><%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%><%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn"%><!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><html>  <head><meta http-equiv="Content-Type" content="text/html; charset=gb2312" /><title>无标题文档</title></head><body  onload="window.show()">  <select class="easyui-combobox" id="years" name="select" panelHeight="auto" style="    width:80px; padding-top:5px; margin-top:10px;">  </select>年  <select class="easyui-combobox" id="months" name="select" panelHeight="auto" style="    width:80px; padding-top:5px; margin-top:10px;"><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> <option value="11">11</option> <option value="12">12</option>     </select>月</body><script type="text/javascript">function show(){var currentMonth = new Date().getMonth();var currentYear = new Date().getFullYear(); document.getElementById("months").value =currentMonth+1; var year = document.getElementById("years");  for (var i = 0; i <= 5; i++) {    var theOption1 = document.createElement("option");                        theOption1.innerHTML = currentYear-i;        theOption1.value = currentYear-i;        year.appendChild(theOption1);           }}</script></html>


下面的是网上的例子:

<%@ page language="java" contentType="text/html; charset=UTF-8"pageEncoding="UTF-8"%><%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%><%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn"%><!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><html>  <head><meta http-equiv="Content-Type" content="text/html; charset=gb2312" /><title>无标题文档</title></head><body  onload="show()">  <select class="easyui-combobox" id="years" name="select" panelHeight="auto" style="    width:80px; padding-top:5px; margin-top:10px;">  </select>年  <select class="easyui-combobox" id="months" name="select" panelHeight="auto" style="    width:80px; padding-top:5px; margin-top:10px;"><option value=7>7</option>  </select>月</body><script type="text/javascript">function show(){    var currentYear = new Date().getFullYear();    var currentMonth = new Date().getMonth();    var year = document.getElementById("years");    var month = document.getElementById("months");    var theOption1 = document.createElement("option");    var theOption2 = document.createElement("option");        for (var i = 0; i <= 11; i++) {    var theOption1 = document.createElement("option");        var theOption2 = document.createElement("option");                        theOption1.innerHTML = currentYear-i;        theOption1.value = currentYear+5-i;        year.appendChild(theOption1);        theOption2.innerHTML = currentMonth+4-i;        theOption2.value = currentMonth+4-i;                month.appendChild(theOption2);    }}</script></html>