不错的一个日期输入 动态(2)


<!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 btnSubmit=document.createElement('BUTTON');
    btnSubmit.style.width='32px';
    parent.insertBefore(btnSubmit,obj);
    btnSubmit.id='LoftyBtn';

    btnSubmit.textContent='OK';
    btnSubmit.value='OK';
    al(btnSubmit,'click','Restore()');
*/    
    OldTextBox=obj;
    parent.removeChild(obj);
    var defaultValue = obj.value;
    var now=new Date();
    var cYear=now.getFullYear();
    SetCurrentYear(selYear,cYear,defaultValue);
    al(selYear,'change','Restore(obj)');
}
function Restore()
{
OldTextBox.value = arguments[0].value;
var yy=document.getElementById('LoftyYear');
var parent=yy.parentNode;
parent.insertBefore(OldTextBox,yy);
parent.removeChild(yy);
/*
    var yy=document.getElementById('LoftyYear');
    var btn=document.getElementById('LoftyBtn');
    var time=yy.options[yy.selectedIndex].value;
    OldTextBox.value=time;
    var parent=yy.parentNode;
    parent.insertBefore(OldTextBox,yy);
    parent.removeChild(yy);
    parent.removeChild(btn);
*/
}
function SetCurrentYear(selecter,currYear)
{
    if(currYear==null){
        currYear=Math.round(selecter.options[selecter.selectedIndex].value);
    }
    var dv = arguments[2];
    reAppendSelect(selecter,1901,2001,currYear,dv);
}
function reAppendSelect(selecter,startIndex,endIndex,selIndex)
{
    while(selecter.options.length>0)
    {
        selecter.removeChild(selecter.options[selecter.options.length-1]);
    }
    for(i=startIndex;i<=endIndex;i++)
    {
        var op=new Option(i,i);
        selecter.options.add(op);
        if(arguments[4]!=""){
            if(i==arguments[4])
                op.selected=true;
        }else{
            if (i==endIndex)
                op.selected=true;
        }
    }

}
function al(obj,lissener,func){
    if(agt.indexOf('firefox')!=-1){
        obj.addEventListener(lissener,function(){eval(func);},false);
    }else{
        obj.attachEvent('on'+lissener,function(){eval(func);});
    }
}


</script>
</head>

<body>
<input onclick="DateSeter(this);" />
</body>
</html>

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/wjjgwg.html