javascript - 如果 Caps Lock 开启,ExtJS 会显示消息
问题描述
如果用户在输入密码时打开大写锁定,我想添加一条消息。这是我到目前为止所尝试的。
{
xtype:'textfield',
itemId: 'field_password_login',
fieldLabel: 'Password',
inputType: 'password',
allowBlank: false,
listeners:
{
keypress: function(tf, e)
{
if (e.getKey() != 13 && e.getKey() != 10 && e.getKey() != 127)
{
if ((!e.shiftKey && (e.getKey() >= 65 && e.getKey() <= 90)) || ((e.getKey() >= 97 && e.getKey() <= 122) && e.shiftKey))
{
Ext.getCmp("app_idCAPSIndicator").setText("CAPS LOCK is ON");
Ext.getDom("app_idCAPSIndicator").style.color = "navy";
}
else
{
Ext.getCmp("app_idCAPSIndicator").setText("");
}
}
if (e.getKey() == 13)
{
Ext.Msg.alert("Enter Pressed");
}
}
}
},
{
xtype: 'label',
fieldLabel: '',
labelWidth: 90,
labelAlign: 'left',
labelSeperator: '',
id: 'app_idCAPSIndicator'
}
但它不起作用。我没有收到任何错误消息来知道发生了什么。我在这里做错了什么?
解决方案
添加 enableKeyEvents: true,此 true 为 HTML 输入字段启用按键事件的代理
{
xtype:'textfield',
itemId: 'field_password_login',
fieldLabel: 'Password',
inputType: 'password',
allowBlank: false,
enableKeyEvents: true,
listeners:
{
keypress: function(tf, e)
{
if (e.getKey() != 13 && e.getKey() != 10 && e.getKey() != 127)
{
if ((!e.shiftKey && (e.getKey() >= 65 && e.getKey() <= 90)) || ((e.getKey() >= 97 && e.getKey() <= 122) && e.shiftKey))
{
Ext.getCmp("app_idCAPSIndicator").setText("CAPS LOCK is ON");
Ext.getDom("app_idCAPSIndicator").style.color = "navy";
}
else
{
Ext.getCmp("app_idCAPSIndicator").setText("");
}
}
if (e.getKey() == 13)
{
Ext.Msg.alert("Enter Pressed");
}
}
}
},
推荐阅读
- html - 修改 jm 微调器点以使其大小相同而没有反弹
- eclipse - 如何通过命令行重新启动或退出我的 Eclipse
- lua - 为什么使用 scipy 从 Lua 火炬和 pytorch 加载 .mat 文件后矩阵之间存在差异?
- python - Dask:在列上删除 NA?
- php - Symfony 中的注解机制——它是如何工作的?
- android-studio - Kotlin REPL:由于可能的重新分配,禁止捕获的成员值初始化
- c# - 通过 OLEDB 连接到 MySQL
- php - 在使用 PHP 中的 IF 语句更新 php 中的表格内容之前如何检查?
- c# - 为什么尝试为 MySql 创建 using 指令会产生“缺少 using 指令”错误?
- r - 在 r 中绘制没有谷歌地图 API 的城市地图