gpt4 book ai didi

javascript - Enter to Tab 脚本没有跳过复选框?

转载 作者:行者123 更新时间:2023-12-03 07:55:25 26 4
gpt4 key购买 nike

我正在尝试将输入转换为选项卡,它与我的表单字段完美配合,但不适用于我的页面上的复选框。有人知道为什么不这样做吗?

输入选项卡代码:

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

关于javascript - Enter to Tab 脚本没有跳过复选框?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34819887/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com