js动态设置select中option选中

    科技2026-02-18  7

    html代码:

    < select id = "sel" > < option value = 1 >op1</ option > < option value = 4 >op4</ option > < option value = 3 >op3</ option > </ select >

    js代码:

    /** * 设置select控件选中 * @param selectId select的id值 * @param checkValue 选中option的值 */ function set_select_checked(selectId, checkValue){ var select = document.getElementById(selectId); for (var i = 0; i < select.options.length; i++){ if (select.options[i].value == checkValue){ select.options[i].selected = true; break; } } } //调用该函数 // 设置select选中该班组 set_select_checked('edit-group', group_id);
    Processed: 0.008, SQL: 9