开发者

How to get value of an option if i know the index - jquery

How to get vale of an option if i know 开发者_开发知识库index of that option.? .Its a list box

<div id="selDiv">
    <select id="opts" multiple="multiple">
            <option selected value="DEFAULT">Default</option>
            <option value="SEL1">Selection 1</option>
            <option value="SEL2">Selection 2</option>
    </select>

if i want to get value of index 1.(ie, SEL1).how can i do this? . and how can i make that option is selected?


$('#opts').find('option').eq(1).attr('selected','selected').val();

And if you want to unselect the first option you would do:

$('#opts').find('option').eq(0).attr('selected',false);



$('#opts').children('option').eq(1).attr('value'); 
$('#opts').children('option').eq(1).attr('selected','selected'); 
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜