select 多选选中

<select id="sel" multiple="multiple">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
</select>

 

// 将 sel 中   value 为 1 或 3 的 options 选中
var values = "1,3";
with (document.getElementById('sel')) {
    for (var i=0; i<options.length; i++) {
        options[i].selected = (','+values+',').indexOf(','+options[i].value+',')>-1;
    }
}

 

posted @ 2016-03-12 17:11  白尼玛砸缸  阅读(540)  评论(0编辑  收藏  举报