最近在写前端的时候,遇到一个问题,想要给指定下标的option值选中,一开始使用了
attr("selected",true) 不生效,后来替换成 prop("selected","selected") 就起作用了,
但是,我还需要实现在 option 选中的同时,触发 select 的change 事件,此时就可以这样写
$("select[name=test] option").eq(0).prop("selected","selected").trigger("change");
即用 trigger 来触发事件