간단한 연월연동

1617 단어 간단하다
HTML
<SELECT NAME="SelTjYear">

</SELECT>

<SELECT NAME="SelTjMonth">

</SELECT>


소스 코드:
function vYearMonth(yearObjId, monthObjId) {

    var selYear = document.getElementById(yearObjId);

    var selMonth = document.getElementById(monthObjId);

    var myDate = new Date(); // 

    var myYear = myDate.getFullYear(); // 

    var myMonth = myDate.getMonth() + 1; // 

    var yearMin = -2; // , 

    var yearMax = 10; // , 



    //Begin *******************************

    selYear.options.add(new Option("", ""));

    for (var i = yearMin; i < yearMax; i++) {

        var opt = new Option(myYear + i, myYear + i);

        selYear.options.add(opt);

    }

    // 1-yearMin , 1 ""

    selYear.options.selectedIndex = 1 - yearMin;

    //End *******************************



    //Begin *******************************

    selMonth.options.add(new Option("", ""));

    for (var i = 0; i < 12; i++) {

        var opt = new Option(i + 1, i + 1);

        selMonth.options.add(opt);

    }

    // 

    selMonth.options.selectedIndex = myMonth;

    //End *******************************





    selYear.onchange = function () {

        if (this.value == "") {

            selMonth.selectedIndex = 0;

        }

        else {

            if (selMonth.value == "") {

                selMonth.selectedIndex = myMonth;

            }

        }

    };

}


호출:
vYearMonth('SelTjYear', 'SelTjMonth');

좋은 웹페이지 즐겨찾기