我正在尝试根据值从选择列表中选择特定选项,我有以下标记:
<select name="class" id="class">
<option value="1">679460ED-0B15-4ED9-B3C8-A8C276DF1C82</option>
<option value="2">B99BF873-7DF0-4E7F-95FF-3F1FD1A26139</option>
<option value="3">1DCD5AD7-F57C-414</option>
<option value="4">6B0170AA-F044-4F9C-8BB8-31A51E452CE4</option>
<option value="5">C6A8B</option>
<option value="6">1BBD6FA4-335A-4D8F-8681-DFED317B8052</option>
<option value="7">727D71AB-F7D1-4B83-9D6D-6BEEAAB</option>
<option value="8">BC4DE8A2-C864-4C7C-B83C-EE2450AF11B1</option>
<option value="9">AIR CONDITIONING SYSTEM</option>
<option value="10">POWER GENERATION SYSTEM</option>
</select>
<script>
selectThisValue('#class',3);
</script>
在.js
function selectThisValue(element,value) {
console.log(value);
var elem = $(element + ' option[value=' + value + ']');
console.log(elem);
elem.attr("selected", "selected");
}
结果console.log
如下:
3
[prevObject: i.fn.i.init[1], context: document, selector: "#class option[value=3]", jquery: "1.10.2", constructor: function…]
但这不起作用,没有给出错误,但也没有任何反应。请帮助确定我在哪里错了。