惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

N
News | PayPal Newsroom
IT之家
IT之家
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
大猫的无限游戏
大猫的无限游戏
GbyAI
GbyAI
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
L
LangChain Blog
S
SegmentFault 最新的问题
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
Project Zero
Project Zero
P
Privacy & Cybersecurity Law Blog
V
Vulnerabilities – Threatpost
博客园 - 三生石上(FineUI控件)
Recorded Future
Recorded Future
The Hacker News
The Hacker News
C
CXSECURITY Database RSS Feed - CXSecurity.com
C
CERT Recently Published Vulnerability Notes
宝玉的分享
宝玉的分享
aimingoo的专栏
aimingoo的专栏
T
Tor Project blog
T
The Exploit Database - CXSecurity.com
Schneier on Security
Schneier on Security
H
Help Net Security
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
M
MIT News - Artificial intelligence
W
WeLiveSecurity
P
Proofpoint News Feed
A
About on SuperTechFans
S
Securelist
I
InfoQ
G
Google Developers Blog
博客园 - 司徒正美
博客园 - 叶小钗
Latest news
Latest news
F
Fortinet All Blogs
G
GRAHAM CLULEY
腾讯CDC
Jina AI
Jina AI
S
Schneier on Security
I
Intezer
V
Visual Studio Blog
美团技术团队
V2EX - 技术
V2EX - 技术
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
The Cloudflare Blog
Microsoft Security Blog
Microsoft Security Blog
Blog — PlanetScale
Blog — PlanetScale
P
Proofpoint News Feed
罗磊的独立博客
Y
Y Combinator Blog

博客园 - 嚣张的沉默

读写txt文档 限制TextBox输入字数 计算TextBox输入的字数 我常用的正则与SQL语句 DataSet导入到Excel 用户控件的传值方法 Repeater模板列 asp.net的几个小技巧 百叶窗效果 建站安全 倒计时代码 解决SQL2000安装服务器挂起 删除.NET的最近项目 屏幕右下角弹出广告 DataSet写入、导出XML 上传图片重命名并创建文件夹 自动跳转页面带参数 微软出的AJAX控件的安装(转载) 第一次开博
年月日联动的JS代码
嚣张的沉默 · 2008-01-25 · via 博客园 - 嚣张的沉默

新建一个JS文件,起个名,把以下代码复制过去

function   YYYYMMDDstart()   
  
{   
          MonHead   
=   [31,   28,   31,   30,   31,   30,   31,   31,   30,   31,   30,   31];   
    
          
//先给年下拉框赋内容   
          var   y       =   new   Date().getFullYear();   
          
for   (var   i   =   (y-30);   i   <   (y-10);   i++)   //以今年为准,显示前30年之后的20年   
                  document.form1.YYYY.options.add(new   Option(""+i+"",   i));   
    
          
//赋月份的下拉框   
          for   (var   i   =   1;   i   <   13;   i++)   
                  document.form1.MM.options.add(
new   Option(""+i+"",   i));   
    
//          document.form1.YYYY.value   =   y;   //获取到当前年份
//
          document.form1.MM.value   =   new   Date().getMonth()   +   1;   获取到当前月份
          var   n   =   MonHead[new   Date().getMonth()];   
          
if   (new   Date().getMonth()   ==1   &&   IsPinYear(YYYYvalue))   n++;   
                  writeDay(n);   
//赋日期下拉框Author:meizz   
//
          document.form1.DD.value   =   new   Date().getDate();   获取到当前日期
  }
   
  
function   YYYYDD(str)   //年发生变化时日期发生变化(主要是判断闰平年)   
  {   
          
var   MMvalue   =   document.form1.MM.options[document.form1.MM.selectedIndex].value;   
          
if   (MMvalue   ==   ""){   var   e   =   document.form1.DD;   optionsClear(e);   return;}   
          
var   n   =   MonHead[MMvalue   -   1];   
          
if   (MMvalue   ==2   &&   IsPinYear(str))   n++;   
                  writeDay(n)   
  }
   
  
function   MMDD(str)     //月发生变化时日期联动   
  {   
          
var   YYYYvalue   =   document.form1.YYYY.options[document.form1.YYYY.selectedIndex].value;   
          
if   (YYYYvalue   ==   ""){   var   e   =   document.form1.DD;   optionsClear(e);   return;}   
          
var   n   =   MonHead[str   -   1];   
          
if   (str   ==2   &&   IsPinYear(YYYYvalue))   n++;   
                  writeDay(n)   
  }
   
  
function   writeDay(n)     //据条件写日期的下拉框   
  {   
          
var   e   =   document.form1.DD;   optionsClear(e);   
          
for   (var   i=1;   i<(n+1);   i++)   
                  e.options.add(
new   Option(""+i+"",   i));   
  }
   
  
function   IsPinYear(year)//判断是否闰平年   
  {       return(0   ==   year%4   &&   (year%100   !=0   ||   year%400   ==   0));}   
  
function   optionsClear(e)   
  
{   
          
for   (var   i=e.options.length;   i>0;   i--)   
                  e.remove(i);   
  }
 

在HTML页里调用此JS文件,并输入以下代码:

<select name="YYYY" onchange="YYYYDD(this.value)">
                
<option value="0">选择年</option>
            
</select>
            
<select name="MM" onchange="MMDD(this.value)">
                
<option value="0">选择月</option>
            
</select>
            
<select name="DD">
                
<option value="0">选择日</option>
            
</select>

在<body>里添加<body onload="YYYYMMDDstart()">

还忘了一件事,本人不知道用客户端控件在aspx.cs页里怎么能接收到值,所以用了一个笨办法,写了一个JS,在提交按钮的时候调用此JS。(如果哪位高人看了嚣张的博客,又知道怎么更好的解决的话,请留言指教,万分感谢)

<script language="javascript" type="text/javascript">
    
function year()
    
{
        
var y=document.getElementById("YYYY").value;
        document.getElementById(
"hidYear").value=y;
        
var m=document.getElementById("MM").value;
        document.getElementById(
"hidMonth").value=m;
        
var d=document.getElementById("DD").value;
        document.getElementById(
"hidDay").value=d;
    }

    
</script>