you need to use trigger to trigger
actively.
$("select").trigger("change");
< hr >
add a little bit, here is an example
https://codepen.io/xboxyan/pe.
The
action is that there is a select , and then I let select switch
by clicking another button.
select itself is also bound to the change event, which will also be triggered
.
<select id="select">
<option>111</option>
<option>222</option>
<option>333</option>
</select>
<button id="btn"></button>
$('-sharpbtn').click(function () {
$('-sharpselect').val('333').trigger('change')
})
$('-sharpselect').on('change',function(ev){
console.log(ev.target.value)
})
$("select option [value='3']"). Attr ('selected',true). Siblings (). Attr (' selected',false)
For the general
idea of
, use the prop method:
$('-sharpstacked-ui-header-wmpw-capacity option:eq(2)').prop('selected', true);
try this
$("-sharpselect_id ").get(0).selectedIndex=1
< hr >
write an example to see if it is the effect you want
https://codepen.io/woaiacj201.
< hr >
I have no problem with the test. Maybe it's the difference between browsers, so there's nothing we can do about it. Be targeted and compatible.
the previous answer is to provide a train of thought
$("-sharpselect option:selected").val('3').change()
this drop-down box has a focus event (bound to document). It is normal to delete this event, indicating that the focus event is responsible. The landlord can take the time to study it. Time is limited, so we won't delve into it. I beg your pardon.