<分区>
我注意到当 Javascript 本身完成更改时,$('#firstId')
的事件没有触发。
为什么会这样?
有没有办法仍然触发事件?
这是一个例子:
$('#firstId').on('change input paste', function(){
console.log("this is the input event being fired");
});
$('#randomButton').on('click', function(){
$('#firstId').val(Math.floor(Math.random()*2147483647 )+1);
console.log("randomButton being fired");
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<span for="firstId">number: </span>
<input type="number" id="firstId"/>
<p>Or</p>
<button id="randomButton">Get a random number</button><br>