我在HTML中有以下输入:
<div class="form-group">
<label for="siretNumber">Numéro de SIRET</label>
<input onkeyup="checkSIRET(this);" onfocusout="ocr_on_fly(true, this, true)" onfocusin="ocr_on_fly(false, this, true);" type="text" class="form-control" id="siretNumber" value="{{ pdf['siret'] }}">
</div>
<div class="form-group">
<label for="sirenNumber">Numéro de SIREN</label>
<input onkeyup="checkSIREN(this)" onfocusout="ocr_on_fly(true, this, true)" onfocusin="ocr_on_fly(false, this, true)" type="text" class="form-control" id="sirenNumber" value="{{ pdf['siret'] }}">
</div>在ocr_on_fly函数上,我需要自动执行onkeyup属性的函数。使用下面的代码,我获得了onkeyup属性的值,但是我如何执行它呢?
let attr = input.getAttribute('onkeyup')
// attr = checkSIRET(this); or attr = checkSIREN(this);提前感谢
发布于 2019-06-05 23:34:29
您可以使用dispatchEvent来触发keyup keyboard event。
input.dispatchEvent(new KeyboardEvent('keyup'));通过以这种方式触发事件,您传递给函数的this-argument与它在正常keyup事件期间的值相匹配。如果需要,您可以传递一个应该由事件报告的特定密钥:
input.dispatchEvent(new KeyboardEvent('keyup', {'key':'a'}));发布于 2019-06-05 23:22:44
https://stackoverflow.com/questions/56463405
复制相似问题