javascript - type="number"时获取input的ENTER点击事件
问题描述
在 HTML输入文本中,使用onKeyUp方法我能够在输入类型=“文本”时捕获输入按钮上的单击事件。
但是如果输入type="number",则无法触发相同的事件。
HTML
<input id="inputLocation" type="text" class="inputBarCode" style="text-transform: uppercase" placeholder: placeholder/>
JS
$('#inputLocation').keyup(function (e) {
if (e.which === 13) {
$('#inputLocation').blur();
//self.executeLocationLookup();
alert("Event ", e.which);
}
});
如果输入类型是数字键盘,你能告诉我如何获取输入按钮的点击事件(13)
解决方案
使用event.target.value
财产或$(this).val()
$('#inputLocation').keyup(function (e) {
if (e.which === 13 && isNumber(e.target.value)) {
$('#inputLocation').blur();
//self.executeLocationLookup();
alert("Event ", e.which);
}
});
function isNumber(n) {
return !isNaN(parseFloat(n)) && isFinite(n);
}
推荐阅读
- nginx - 带有 uwsgi、flask 和 slimxmpp 的 Nginx 服务器
- jquery - 使用 PivotTable.js 在总列中显示平均值
- excel - 如何阻止更改预先格式化的excel中的格式?
- r - “{123, affdsf, 223, 22, dgbwa, 33333}”的格式是什么?
- c# - 在 ASP.NET 中设置日常工作
- windows - Windows 10 平板电脑上的 Windows 窗体应用程序?
- angular - nGINX / Angular 4 HTTP 第一次加载性能
- javascript - 不是 googlemaps api javascript 中的函数错误
- mysql - 如何在 Jasper 上显示多行数据
- ios - Swinject 容器注册失败