Javascript函数移动到表格中的下一个textarea进入按下 [英] Javascript function to move to next textarea in table on enter press

查看:70
本文介绍了Javascript函数移动到表格中的下一个textarea进入按下的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,我对表格中的textareas有疑问。我想当用户按下回车键时,焦点应该转到表格中的下一个启用的textarea ...我设法在用户输入时覆盖textarea的默认动作,现在只需要焦点转到下一个启用textare,所有textareas都在彼此之下。任何帮助将非常感谢,请提前感谢。

Hi all, i have a query regarding textareas in a table. I want when the user presses enter, the focus should go to the next enabled textarea in the table...i managed to override the default action of a textarea when a user presse enter, just need now for the focus to go to the next enabled textare, all textareas are right underneath each other.Any help will be much appreciated, thanking you in advance.

推荐答案

想出一种使用简单的javascript做的方法这个,通过使用'name'属性并给每个textarea增加一个id。这是我所做的功能



Figured out a way to use simple javascript to do this, by using the 'name' attribute and giving each textarea an incrementing id. This is the function i made

function enterPress(currentTextarea){

var key = window.event.keyCode;

 if(key == 13){

   var areas = document.getElementsByName('textareas');
   var current_id = currentTextarea;
   
   for(var i =0; i < areas.length; i++){
      
      var next_id = areas[i].id;

      if((next_id > current_id) && (!areas[i].disabled){//checks for next enabled textarea
         
         areas[i].focus();

         window.event.preventDefault();//prevent normal textarea behaviour when enter is pressed

         return;
      }
   }
   
 }

}


这篇关于Javascript函数移动到表格中的下一个textarea进入按下的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆