这是代码:
<select class="dd-select" name="UM_Status_Engraving" id="UM_Status_Engraving" onchange="colourFunction(this)">
<option class="dd-select" value="SELECT">SELECT</option>
<option class="dd-ok" value="OK">OK</option>
<option class="dd-notok" value="NOT OK">NOT OK</option>
</select>
onchange="colourFunction(this)"
设置一个类来选择选项的下拉列表,它在我选择下拉选项时有效,但是当我动态设置选项时,它不会调用onchange
所以选项类没有设置下拉......有人帮忙...
答案 0 :(得分:0)
当您更改选择的值时,也会自行触发change()
。
function colourFunction(ele){
console.log(ele.value)
}
$('#UM_Status_Engraving').val('OK').trigger('change')
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<select class="dd-select" name="UM_Status_Engraving" id="UM_Status_Engraving" onchange="colourFunction(this)">
<option class="dd-select" value="SELECT">SELECT</option>
<option class="dd-ok" value="OK">OK</option>
<option class="dd-notok" value="NOT OK">NOT OK</option>
</select>