开发者

jquery Setting option selected with known value

I have the next select:

<select name="priority" id="priority" class="update_priority">
    <option value="ro开发者_StackOverflowot" label="Without parent">Without parent</option>
    <option value="72" label="Rank3">Rank3</option>
    <option value="71" label="Rank1">Rank1</option>
    <option value="67" label="Rank2">Rank2</option>
    <option value="64" label="Rank4">Rank4</option>
</select>

In JS i have a variable with something value. For example:

selected = 71;

Now, with help of jQuery I want to make option selected with this value(in our example 71).


you don't need jquery for this. you can just use plain old javascript:

document.getElementById("priority").value = "71";

But if you still want to with jquery you can do the same thing:

$("#priority").val("71")

EDIT: Here is an example. You can comment out either one you want to see the other one work: http://jsfiddle.net/BupWA/

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜