JS实现年份下拉框select选择器

var options = "";
        function setYears() {
            //设置年份的选择
            var myDate = new Date();
            var startYear = myDate.getFullYear() - 5;//起始年份
            var endYear = myDate.getFullYear();//结束年份
            var obj = document.getElementById('selectTime');
            for (var i = startYear; i <= endYear; i++) //循环年份,动态生成option列表,拼接html
            {
                if (myDate.getFullYear() == i) {
                    options += '';
                } else {
                    options += '';
                }

            }
            $("#selectTime").html(options);  //根据选择器设置其html
        }

 

你可能感兴趣的:(项目实战笔记)