首页 > 代码库 > JS Select 月日日期联动
JS Select 月日日期联动
Js对Select控件进行联动操作,一个select选择月份后另一个select生成对应月份的所有日期。
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %><!DOCTYPE html><html xmlns="http://www.w3.org/1999/xhtml"><head runat="server"> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title></title> <script type="text/javascript"> window.onload = initForm; function initForm() { document.getElementById("months").selectedIndex = 0; document.getElementById("months").onchange = populateDays; } function populateDays() { var monthDays = new Array(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31); var monthStr = this.options[this.selectedIndex].value; if (monthStr != "") { var theMonth = parseInt(monthStr); document.getElementById("days").options.length = 0; for (var i = 0; i < monthDays[theMonth]; i++) { document.getElementById("days").options[i] = new Option(i + 1); } } } </script> </head><body> <form id="form1" runat="server"> <div> <select runat="server" id="months"> <option value=http://www.mamicode.com/"">Month</option> <option value=http://www.mamicode.com/"0">January</option> <option value=http://www.mamicode.com/"1">February</option> <option value=http://www.mamicode.com/"2">March</option> <option value=http://www.mamicode.com/"3">April</option> <option value=http://www.mamicode.com/"4">May</option> <option value=http://www.mamicode.com/"5">June</option> <option value=http://www.mamicode.com/"6">July</option> <option value=http://www.mamicode.com/"7">August</option> <option value=http://www.mamicode.com/"8">September</option> <option value=http://www.mamicode.com/"9">October</option> <option value=http://www.mamicode.com/"10">November</option> <option value=http://www.mamicode.com/"11">December</option> </select> <select runat="server" id="days"> <option>Day</option> </select> </div> </form></body></html>
JS Select 月日日期联动
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。