Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/398.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
用于创建类似excel的光标移动的Javascript_Javascript_Php_Jquery - Fatal编程技术网

用于创建类似excel的光标移动的Javascript

用于创建类似excel的光标移动的Javascript,javascript,php,jquery,Javascript,Php,Jquery,我有下面的表单来获取用户输入并更新mysql表。因为下表中大约有25行,每行大约有7个输入框。我需要一个简单的javascript函数来使用箭头键在水平和垂直方向上移动输入框。目前只能使用制表符,制表符从左到右连续移动,很麻烦。我发现了一些可编辑的网格,但它们很复杂,我知道如何处理数据,只需要四处移动。提前谢谢 NoeleLocation氚剂量率(mGy/h) (DAC)部件(DAC)碘(DAC)表面含量(Bq/cm2) 通过给每个可编辑的输入字段一个唯一的ID,您有了一个正确的开始。但是,您

我有下面的表单来获取用户输入并更新mysql表。因为下表中大约有25行,每行大约有7个输入框。我需要一个简单的javascript函数来使用箭头键在水平和垂直方向上移动输入框。目前只能使用制表符,制表符从左到右连续移动,很麻烦。我发现了一些可编辑的网格,但它们很复杂,我知道如何处理数据,只需要四处移动。提前谢谢

NoeleLocation氚剂量率(mGy/h) (DAC)部件(DAC)碘(DAC)表面含量(Bq/cm2)


通过给每个可编辑的
输入
字段一个唯一的ID,您有了一个正确的开始。但是,您也有一个错误,当
循环处理多行时,最后5个ID(例如,
ID='dose'
)将被复制,并且它们需要不同。我建议您将所有的
id=
更改为
name=
,并为它们提供类似但仍然唯一的id,例如
id='AA'
id='AB'
id='BA'
等等。然后,在javascript中,您可以使用如下方式获取整个二维输入对象数组:

var cels, x, y;  //globals
cels=[];
for(x=0; x<7; x++)
{ tmp="ABCEDFG".substr(x,1);
  cels[x]=[];
  for(y=0; y<25; y++)
    cels[x][y]=document.getElementById(tmp+"ABCDEFGHIJKLMNOPQRSTUVWXY".substr(y,1));
}
function tstkey(e, i)
{ x="ABCDEFG".indexOf(i.substr(0,1));
  y="ABCDEFGHIJKLMNOPQRSTVWXY".indexOf(i.substr(1,1));
  if(e.keyCode == 13)     //Enter key pressed?
  { x++;        //index of next cell in current row
    if(x>6)     //off the end?
    { x=0;      //first cell
      y++;      //next row
      if(y>24)  //off the end?
        y=0;    //first row
  } }
//    if(e.keyCode == down-arrow, up-arrow, etc )
//      do appropriate manipulation of x and y coordinates   

  cels[x][y].focus();  //move cursor to other cell in 2D array of input fields
  return;
}
该函数将如下所示:

var cels, x, y;  //globals
cels=[];
for(x=0; x<7; x++)
{ tmp="ABCEDFG".substr(x,1);
  cels[x]=[];
  for(y=0; y<25; y++)
    cels[x][y]=document.getElementById(tmp+"ABCDEFGHIJKLMNOPQRSTUVWXY".substr(y,1));
}
function tstkey(e, i)
{ x="ABCDEFG".indexOf(i.substr(0,1));
  y="ABCDEFGHIJKLMNOPQRSTVWXY".indexOf(i.substr(1,1));
  if(e.keyCode == 13)     //Enter key pressed?
  { x++;        //index of next cell in current row
    if(x>6)     //off the end?
    { x=0;      //first cell
      y++;      //next row
      if(y>24)  //off the end?
        y=0;    //first row
  } }
//    if(e.keyCode == down-arrow, up-arrow, etc )
//      do appropriate manipulation of x and y coordinates   

  cels[x][y].focus();  //move cursor to other cell in 2D array of input fields
  return;
}
请注意,使用此代码,您需要一个SUBMIT按钮将数据发送到Web服务器。此外,由于这更多的是一个建议,而不是一个完整详细的答案,我还没有测试代码的拼写错误等。对浏览器内置javascript调试器的一些实验将揭示向上箭头、向下箭头等的键代码