我在表单中的所有输入都textarea
带有 class 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
}
});