经过大量调试后,我找到了无法在表单字段中输入任何文本的原因。
我有一个 jQuery 函数来捕获我在 JS 应用程序中使用的一些键。
$(document).bind 'keyup keydown', (e) ->
shifted = e.shiftKey
cntrled = e.metaKey || e.ctrlKey
Javascript:
$(document).bind('keyup keydown', function(e) {
shifted = e.shiftKey;
return cntrled = e.metaKey || e.ctrlKey;
});
为什么我无法在表单字段中输入内容?
一旦删除该部分,我就可以再次输入。
最佳答案
您返回的值 cntrled 会取消事件。
在 Coffeescript 中,将返回函数中的最后一个值。
返回 true 作为处理程序中的最后一行。
JavaScript 相当于你现在正在做的事情......
$(document).bind('keyup keydown', function (e) {
var shifted = e.shiftKey
, cntrled = e.metaKey || e.ctrlKey;
return cntrled;
});
将其更改为...
$(document).bind('keyup keydown', function (e) {
var shifted = e.shiftKey
, cntrled = e.metaKey || e.ctrlKey;
return true;
});
关于jQuery 绑定(bind) keyup、keydown - 无法在表单字段中输入内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14518192/