码迷,mamicode.com
首页 > Web开发 > 详细

Js Select动态添加Option

时间:2015-05-19 18:43:14      阅读:123      评论:0      收藏:0      [点我收藏+]

标签:

 var now = new Date();

    function setDate(type, id, from, to) {
        var str = "";
        for (var i = from; i < to + 1; i++) {
            if ((type == "y" && i == now.getFullYear()) || (type == "m" && i == now.getMonth() + 1) || (type == "d" && i == now.getDate()))
                str = str + "<option selected=‘selected‘>" + i + "</option>";
            else
                str = str + "<option>" + i + "</option>";
        }
        document.getElementById(id).innerHTML = str;
    }
  

 setDate("d", "day2", 1, 31);

    function $() {
        var elements = new Array();
        for (var i = 0; i < arguments.length; i++) {
            var element = arguments[i];
            if (typeof element == ‘string‘)
                element = document.getElementById(element);
            if (arguments.length == 1)
                return element;
            elements.push(element);
        }
        return elements;
    }

就这么简单,不谢。1972年2月出生的八字格局

Js Select动态添加Option

标签:

原文地址:http://www.cnblogs.com/yonsy/p/4514976.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!