标签:javascrip asc sel UNC handler sele var function isp
除用户人为交互触发事件外,用js脚本触发事件的一般流程为
var e = Event(‘event_name‘, {key: value, ...})
event.target
EventHandler
<select >
<option value="all" selected>all</option>
<option value="active">active</option>
<option value="completed">completed</option>
</select>
<script>
let select = document.getElementsByTagName(‘select‘)[0];
select.onchange = handleChange;
function handleChange(e){
console.log(‘changed‘);
}
</script>
如上脚本中的 change 事件脚本触发的方式如下:
var e = Event(‘change‘, {bubbles: true});
select.options[1].dispatchEvent(e);
标签:javascrip asc sel UNC handler sele var function isp
原文地址:https://www.cnblogs.com/zhaofeng-shu33/p/10351963.html