我想在点击按钮时将'a'添加到输入值
这是我的代码(使用jQuery 1.4.4):
$("#button").click(function(){
$("#input").trigger("focus");
var e = jQuery.Event("keypress");
e.which = '97';
$("#input").trigger(e);
})
Run Code Online (Sandbox Code Playgroud)
然而,它似乎只是触发'焦点'事件,但未能'按键'.
Rei*_*gel 12
像这样??对不起,我对你的作品感到困惑..
$("#button").click(function(){
$("#input").trigger("keypress") // you can trigger keypress like this if you need to..
.val(function(i,val){return val + 'a';});
});
Run Code Online (Sandbox Code Playgroud)
reference:.val(function(index,value));
| 归档时间: |
|
| 查看次数: |
48230 次 |
| 最近记录: |