输入到选项卡脚本不会传递复选框

Enter to Tab script does not pass over a checkbox?

本文关键字:复选框 脚本 选项 输入      更新时间:2023-09-26

我正在尝试将输入转换为选项卡,它与我的表单字段完美配合,但不适用于页面上的复选框。 任何人都有任何想法,为什么不呢?

输入到选项卡代码:

<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>

邪恶复选框 :

<input class="case" type="checkbox" onkeyup="return tabE(this,event);"/>

编辑: (HTML 代码) :

<td> <input class="case" type="checkbox" onkeypress="return tabE(this,event);"/> </td>

jquery :

 html += '<td><input class="case" id="caseNo_'+i+'" type="checkbox"/></td>';

它对我有用。现在更新以显示如果动态创建复选框,它将继续工作。

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;
  }
}
var lId = 0;
$(function () {
  $('#addNewCheck').on('click', function(e) {
    lId +=1;
    $('<input id="' + lId + '" class="case" type="checkbox" onkeypress="return tabE(this,event);"/>').insertAfter(':checkbox:last');
  });
});
<script src="http://code.jquery.com/jquery-1.11.3.js"></script>
<form action="action_page.php">
    First name:<br>
    <input type="text" name="firstname" value="Mickey" onkeypress="return tabE(this,event);"><br>
    Last name:<br>
    <input type="text" name="lastname" value="Mouse" onkeypress="return tabE(this,event);"><br><br>
    Case:<br>
    <input class="case" type="checkbox" onkeypress="return tabE(this,event);"/>
    <br>
    <input type="submit" value="Submit" onkeypress="return tabE(this,event);">
</form>
<br>
<button id="addNewCheck">Add new  checkbox </button>