[英]What javaScript code can I use so that the tab key skips one tabindex and the carrage return key skips X tabindexes?
I am an amateur coder and javaScript novice (or less), and I am trying to build an online form with multiple (many) <textarea>
inputs. 我是一名业余编码员和javaScript新手(或更少),并且我正在尝试构建具有多个(许多)
<textarea>
输入的在线表单。
For arguments sake , let's presume it is a 3 x 3 type orientation: 出于参数缘故,我们假设它是3 x 3的类型方向:
For reasons of other functionality & performance, I must use <textarea>
and not <inputs>
. 由于其他功能和性能,我必须使用
<textarea>
而不是<inputs>
。
If a person presses [TAB], then as expected the tab-index is adhered to with no worries ( A1 --> B1 ). 如果有人按下[TAB],则不出所料地遵循Tab索引(A1-> B1)。
If a person pressed [RETURN], because it is a <textarea>
, it adds the \\n delimiter, breaks the line and remains within the still focused <textarea>
. 如果有人按下[RETURN],因为它是一个
<textarea>
,它将添加\\ n分隔符,中断换行并保留在仍集中的<textarea>
。
What I would like to happen is that when a person presses [RETURN], then three tab-indexes are 'skipped' (if that is the right word), and the focus goes to the <textarea>
directly below the previous focused <textarea>
. 我想发生的事情是,当一个人按下[RETURN]时,将“跳过”三个制表符索引(如果这是正确的词),并且焦点将移到
<textarea>
先前聚焦的<textarea>
下方的<textarea>
<textarea>
。
Example: I am in A1; 例如:我在A1; I write/input something;
我写/输入一些东西; I press [RETURN];
我按[RETURN]; I am taken directly to A2.
我直接被带到A2。
[[UPDATE]] [[更新]]
Example of the HTML text area code: HTML文本区号示例:
<textarea data-id="0" class="inputArea colorInput" id="dataInput_0" name="colorInput_row_1" onFocus="classFocused();" onBlur="classBlured();" onKeyUp="splitInput();"></textarea>
Use the jQuery javascript framework, attach key press event listeners to your text areas and if the key pressed is [ENTER] (key code 13) then you shift focus to the field you want (preferably you set IDs for text areas to identify them easily). 使用jQuery javascript框架,将按键事件监听器附加到您的文本区域,如果按下的键是[ENTER](按键代码13),则将焦点转移到所需的字段(最好为文本区域设置ID以轻松识别它们) )。
HTML 的HTML
<textarea class="ta" data-id="1"></textarea>
<textarea class="ta" data-id="2"></textarea>
<textarea class="ta" data-id="3"></textarea>
<textarea class="ta" data-id="4"></textarea>
<textarea class="ta" data-id="5"></textarea>
<textarea class="ta" data-id="6"></textarea>
<textarea class="ta" data-id="7"></textarea>
<textarea class="ta" data-id="8"></textarea>
<textarea class="ta" data-id="9"></textarea>
Javascript Java脚本
$(document).ready(function(){
//attach the event listener on your text areas
$('.ta').keypress(function(e){
if (e.keyCode == 13) //check if [enter] was pressed
{
var currentID = $(this).attr('data-id'); //get the ID of the text area where this happened
if (currentID < 7) $('.ta[data-id="' + (currentID + 3) + '"]').focus(); //if there are other text areas down the line, shift the focus
}
});
})
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.