2017-01-15 33 views
1

我有一个选项列表。当我点击按钮它必须改变第二个选项从“level.value”,但第一个选项也改变了。如何更改jquery的选项

<div id="containerForLevel"> 
    <label for="levelImpotance">The Level of a importance: </label> 
    <select id="levelImpotance"> 
    <option value="#36BBCE">normal</option> 
    <option value="#FFD700">important</option> 
    <option value="#D2006B">very_important</option> 
    </select> 
</div> 
<div id="button"><input type='button' value='Click'></div> 

$("#button").click(edit); 
function edit() { 
    var level = {value:"important"}; 
    $("#levelImpotance :selected").text(level.value);  
} 

https://jsfiddle.net/CrashReactor/9hn38u5f/

如何更改对“level.value”选项当我点击按钮?

回答

0

只需使用val

var secondOptionValue = $("#levelImpotance option").eq(1).val(); 
$("#levelImpotance").val(secondOptionValue);