将选项加载到下拉列表中

时间:2017-04-05 11:26:07

标签: javascript jquery html

我目前正在研究一段代码,它应该将选项附加到下拉列表中;引用的下拉列表未填充。

teamsDropDown = #id;
function loadDropDown(data, teamsDropDown)
{
    var defaultValue;

    teamsDropDown.find("option").remove();
    var list = teamsDropDown;

    jQuery.each(data, function(index, item) {
        var listOptions = list;
        listOptions[listOptions.length] = new Option(item.Name, item.Value.replace(new RegExp("'", "g"), "'"));
        if (item.IsDefaultValue) {
            defaultValue = item.Value;
        }
});
teamsDropDown.val(defaultValue).attr("selected", "selected");
}

function HTMLOptionElementFactory (text, value, defaultSelected, selected) {
    /// <signature>
    /// <param name='text' type='String' optional='true' />
    /// <param name='value' type='String' optional='true' />
    /// <param name='defaultSelected' type='Boolean' optional='true' />
    /// <param name='selected' type='Boolean' optional='true' />
    /// </signature>
    return Object.create(HTMLOptionElement);
}

0 个答案:

没有答案