我有以下代码:
$("#zipCodeInputEl").val("84604");
在我插入值 84604
后,按下提交按钮,但出现错误,因为它没有验证我的值值(value)。但是,如果我删除一些插入的值并从键盘插入它,它就会验证我的值。
<div _ngcontent-c3="" class="welcome-scene__foreground">
<form _ngcontent-c3="" novalidate="" class="ng-pristine ng-invalid ng-touched">
<label _ngcontent-c3="" class="label" for="zipCodeInputEl">ZIP Code</label>
<input _ngcontent-c3="" numericvalidator="true" class="input input--inverse ng-pristine ng-invalid ng-touched" id="zipCodeInputEl" maxlength="5" name="zipCodeInputEl" required="" type="text">
<button _ngcontent-c3="" class="btn btn--welcome btn--stretched" id="btnStart" preventdoublesubmit="">Get Started</button>
</form>
</div>
$(document).ready(function() {
$("#zipCodeInputEl").val("84604");
});
$(document).ready(function() {
$("#btnStart").trigger("click");
});
最佳答案
if I delete a number of the inserted value and insert it from the keyboard, it validates my value.
所以技巧是在输入元素上触发 input
事件来模拟用户操作...
试试这个:
$(document).ready(function() {
$("#zipCodeInputEl").val("84604").trigger("input");
$("#btnStart").trigger("click");
});
关于javascript - 将事件插入输入 jQuery 后如何触发事件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52905845/