我想在单击按钮时将“a”添加到输入值
这是我的代码(使用 jQuery 1.4.4):
$("#button").click(function(){
$("#input").trigger("focus");
var e = jQuery.Event("keypress");
e.which = '97';
$("#input").trigger(e);
})
但是,似乎只触发了“focus”事件,而未能触发“keypress”。
最佳答案
我使用了trigger方法:
$('#selector').val(quantity).trigger("input");
关于jquery - 如何用 jQuery 触发输入事件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15545557/