var event = new Event('input')不生效
```<div class="mt-select" data-item-editable="true" data-listener="true" data-has-val="true" data-enter-empty="true">
<input class="mt-input nop-ctrl mt-valdate__error" id="nop_fieldd_102_16" data-validate-type="3-1"
data-validate-rules="requiredTrim" data-validate-name="隐患一级细分" data-rulename-requiredtrim="" placeholder=""
style="" value="" autocomplete="off" data-item-value="" title="">
<i class="mt-validate__error-icon" style="top: 0px; left: 0px;"></i>
<div class="mt-select__input-arrow">
<div class="mt-select__input-arrowi"></div>
</div>
<div class="mt-select__s-panel" style="position: fixed;">
<a class="mt-select__s-close"></a>
<div class="mt-select__s-panel-content">
<ul class="mt-select__s-panel-ul">
<li class="mt-select__s-panel-li " data-item-value="管线隐患">
<a style="display:none;" pinyin-abbr="GXYH">GUANXIANYINHUAN</a>
<span class="mt-select__s-panel-litext">管线隐患</span>
</li>
<li class="mt-select__s-panel-li " data-item-value="配套隐患">
<a style="display:none;" pinyin-abbr="CHSHPTYH">CHUANSHUPEITAOYINHUAN</a>
<span class="mt-select__s-panel-litext">配套隐患</span>
</li>
</ul>
</div>
</div>
</div>
```
```
var event = new Event('input');
document.querySelector('input').value="管线隐患";
document.querySelector('input').dispatchEvent(event)
setTimeout(500)
```
```
``` [油猴脚本开发指南]元素规则校验和检测的触发
https://bbs.tampermonkey.net.cn/thread-1250-1-1.html
要自己调他都监听了什么监听器
并且按顺序触发的
可以参考文章我是如何推导element的事件顺序的 专门把触发事件放到一个方法里面,直接把dom元素传入就可以。但是我们使用的时候要灵活点。有些时候触发下面这些事件不是一次性触发的。比如onChange.我可能是先focus以后。一断时间才可以触发onChange
const triggerInput = (dom) => {
let myFocus = new Event('focus')
let myInput = new Event('input')
let myChange = new Event('change')
let myBlur = new Event('blur')
dom.dispatchEvent(myFocus)
dom.dispatchEvent(myInput)
dom.dispatchEvent(myChange)
dom.dispatchEvent(myBlur)
} wwwwwllllk 发表于 2022-12-31 16:40
专门把触发事件放到一个方法里面,直接把dom元素传入就可以。但是我们使用的时候要灵活点。有些时候触发下 ...
也是一个很好的想法
页:
[1]