【发布时间】:2013-01-01 04:38:20
【问题描述】:
我在表单中的所有输入都是textarea,类为large。
我正在尝试以下方法,但它不起作用:
if(e.which == 9){ // tab
$(this).next('textarea.large').focus();
}
我试过了
$next = $(":textarea:eq(" + ($(":textarea").index(this) + 1) + ")"); $next.focus();
无济于事(:textarea 不是有效的伪元素),以及其他一些变体。
我也试过这个:
$(this).next(':input').focus();
我在 SO 上检查了其他代码,但它似乎专注于 input type='text',并且似乎不适用于我的 textareas。
是否没有简单直接、跨浏览器兼容的方式来获取表单中的所有文本区域并转到下一个?其中一些文本区域将是动态创建的,因此它们不会在第一次加载页面时都存在。但是 tab 需要对所有这些都有效。
编辑
这很容易在一个简单的小提琴中解决,但问题是,我在以下条件和事件中发生了一些其他事情:
jQuery(document).on('keydown blur','textarea.large',function(
if (e.which == 13 || e.type=='focusout' || e.type=='blur' || e.which == 32) //32 is space
{ ... a bunch of stuff on the page, which naturally takes focus out of the current input
}
});
【问题讨论】:
-
你能为此创建并发布一个小提琴吗?
标签: javascript jquery forms tabs next