首页 > 开发 > JS > 正文

不错的一个日期输入 动态

2024-09-06 12:44:36
字体:
来源:转载
供稿:网友

代码如下:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>日期控件</title>
<script>
var agt = navigator.userAgent.toLowerCase();
var OldTextBox;
function DateSeter(obj){
    var parent=obj.parentNode;

    var selYear=document.createElement('SELECT');
    selYear.id='LoftyYear';
    parent.insertBefore(selYear,obj);
    var selMonth=document.createElement('SELECT');
    selMonth.id='LoftyMonth';
    parent.insertBefore(selMonth,obj);
    var selDay=document.createElement('SELECT');
    selDay.id='LoftyDay';
    parent.insertBefore(selDay,obj);
    var btnSubmit=document.createElement('BUTTON');
    btnSubmit.style.width='22px';
    parent.insertBefore(btnSubmit,obj);
    btnSubmit.id='LoftyBtn';
    for(s in btnSubmit)
    {
//document.write(s+'<br />');
    }
    btnSubmit.textContent='OK';
    btnSubmit.value='OK';
    al(btnSubmit,'click','Restore()');
    OldTextBox=obj;
    parent.removeChild(obj);

    var now=new Date();
    var cYear=now.getFullYear();
    SetCurrentYear(selYear,cYear);
    al(selYear,'change','SetCurrentYear(document.getElementById(/'LoftyYear/'))');
    al(selMonth,'change','SetDay(null,null)');
    for(i=1;i<=12;i++)
    {
        var op=new Option(i,i);
        selMonth.options.add(op);
    }
    var cMonth=now.getMonth()+1;
    SetDay(cYear,cMonth);
    selDay.selectedIndex=now.getDate()-1;
}
function Restore()
{
    var yy=document.getElementById('LoftyYear');
    var mm=document.getElementById('LoftyMonth');
    var d=document.getElementById('LoftyDay');
    var btn=document.getElementById('LoftyBtn');
    var time=yy.options[yy.selectedIndex].value+'-'+mm.options[mm.selectedIndex].value+'-'+d.options[d.selectedIndex].value;

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表