曹永思

导航

Js Select动态添加Option

 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;
    }

就这么简单,不谢。

posted on 2015-05-19 16:59  曹永思  阅读(701)  评论(0编辑  收藏  举报