您的位置:首页 > Web前端 > JavaScript

JavaScript初始化select控件并设置默认选中项

2017-02-20 10:04 387 查看
<div style="float: right;">

    <select name="" id="selectCountry" style="padding:0;">

    </select>

</div>

_initSelectBox: function () {

    var selectCountryNode = document.getElementById("selectCountry");

    var selectCountryChild;

    for (var i = 0; i < countryInfo.length; i++) {

        selectCountryChild = document.createElement("option");

        selectCountryNode.appendChild(selectCountryChild);

        selectCountryChild.innerHTML = "<option value=''>" + countryInfo[i]["CountryName"] + "</option>";

    }

    if (selectCountryNode.childNodes.length > 0) {

      selectCountryNode.selectedIndex = 0;  //默认选中第一项

    }

},

4000
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  JavaScript Web HTML select
相关文章推荐