0

我通过以下方式向选择菜单添加新选项:

var options1 = {
    val1 : 'text1',
    val2 : 'text2'
};
$.each(options1, function(val, text) {
    $('#SelectMenu').append( new Option(text,val) );
});

我们如何设置 JQM 中可用的默认选择选项和 optgroup 选项等属性?

4

1 回答 1

2

现场示例:http: //jsfiddle.net/rULKH/5/

<div data-role="page" data-theme="b" id="option-page"> 
    <div data-role="content"> 

        <div data-role="fieldcontain"> 
            <label for="SelectMenu" class="select">Select Menu</label> 
            <select name="SelectMenu" id="SelectMenu"> 
                <option value="standard">Standard: 7 day</option> 
                <option value="rush">Rush: 3 days</option> 
                <option value="express">Express: next day</option> 
                <option value="overnight">Overnight</option> 
            </select> 
        </div> 

    </div>
</div>

JS

var options1 = {
    val1 : 'text1',
    val2 : 'text2'
};

$.each(options1, function(val, text) {
    $('#SelectMenu').append(new Option(text,val)).val( val ).attr('selected',true).selectmenu("refresh");
});
于 2011-06-15T21:31:19.633 回答