我有以下代碼輸入鍵:addNewRow與通過javascript
$(document).on('keypress', ".addNewRow", function(e){
var keyCode = e.which ? e.which : e.keyCode;
if(keyCode == 9) addNewRow();
});
在按下「選項卡」代碼執行addNewRow(這增加了表的數據)。這工作完美。我想改變這種以使其與「進」工作,使我作如下修改:
$(document).on('keypress', ".addNewRow", function(e){
var keyCode = e.which ? e.which : e.keyCode;
if(keyCode == 9,13) addNewRow();
});
對於一些奇怪的原因,預計今年不起作用。有沒有不同的方式來做到這一點,我失蹤了? *在撞牆頭
編輯:也曾經嘗試這樣做:
$(document).on('keypress', ".addNewRow", function(e){
var keyCode = e.which ? e.which : e.keyCode;
if(keyCode == 9||13) addNewRow();
});
表單代碼(爲了防止提交上輸入):
<script type="text/javascript">
function tabE(obj, e) {
var e = (typeof event != 'undefined') ? window.event : e; // IE : Moz
var self = $(obj),
form = self.parents('form:eq(0)'),
focusable, next;
if (e.keyCode == 13) {
focusable = form.find('input,a,select,button,textarea').filter(':visible');
next = focusable.eq(focusable.index(obj) + 1);
if (!next.length) {
next = focusable.first();
}
next.focus();
return false;
}
}
</script>
<!-- Prevent Enter from Submitting Form -->
<script>
$(document).on("keydown", "input", function(e) {
if (e.which==13) e.preventDefault();
});
</script>
<!-- Begin page content -->
試試 「的keyCode == || 9 ==鍵代碼13」 – Mic