如何按ID设置下拉选项值

时间:2016-11-11 06:49:57

标签: javascript jquery html select dropdown

<select id=workTypeSelection>
    <option id="-1">-Select a Work Type-</option>
    <option id="1">Common</option>
    <option id="3">Computer Maintenance</option>
    <option id="5">Facility Maintenance</option>
    <option id="19">Furniture Move</option>
    <option id="85">Global Work Type</option>
    <option id="24">Lease Request</option>
    <option id="21">Move Responsibility</option>
    <option id="20">Purchase Request</option>
    <option id="16">SLA Maintenance</option>
    <option id="60">Test 123</option>
    <option id="72">TEST J</option>
    <option id="73">test jj</option>
    <option id="65">TEST JOS</option>
</select>

如何使用页面上的jquery在“下拉列表”中选择“测试123”作为当前选择的选项使用选项id-&gt; 60。

1 个答案:

答案 0 :(得分:4)

从下面试试,

$('select option[id="<your_value>"]').attr("selected",true)

$('#selectTagId option[id="<your_value>"]').attr("selected",true)

$('.selectTagClass option[id="<your_value>"]').attr("selected",true)