我试图做到这一点,以便当我单击按钮时输入一个键,我试图让 /
键工作。当前其代码值 (191) 正在输入 ¿。有什么想法吗?
$("button").click(function() {
$("input").focus();
var e = jQuery.Event("keydown");
e.which = 191; // # Some key code value
$("input").val(String.fromCharCode(e.which));
$("input").trigger(e);
});
$('input').keydown(function(e){
console.log('Yes keydown triggered. ' + e.which)
});
HTML:
<input type="text">
<button>button</button>
最佳答案
http://jsfiddle.net/scottux/83GTf/
$("button").click(function() {
$("input").focus();
var e = jQuery.Event("keydown");
e.which = 47; // # Some key code value
$("input").val(String.fromCharCode(e.which));
$("input").trigger(e);
});
$('input').keypress(function(e){
console.log('Yes keydown triggered. ' + e.which)
});
按键事件使用正确的键码。
关于javascript - 单击按钮时的 jQuery 正斜杠,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22924204/