将光标聚焦到每行的第一个文本框 [英] Focusing the cursor to the first text box of Each row

查看:101
本文介绍了将光标聚焦到每行的第一个文本框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述




每当我在

第二个文本框中按下两个标签时我写了代码来生成一个新行文本框。它工作正常。但我的问题是

在我按Tab键时创建的新行中,光标应该在第一个

文本框中。我为此编写了代码。它是第10行和第11行。

它不起作用。请让我知道解决方案。

当我在第一行的第二个文本框中按Tab键时,光标将转到第二行的第二个文本框,当我按第二个文本中的tab时第二排光盘完全没有看到。>
我花了很多时间在这上面。



提前致谢。

html文件如下。


< html>

< ; head>

< script>

var numOfLines = 2;

函数generateRow()

{

var d = document.getElementById(" div");

d.innerHTML + ="< input type =''text''name =''quantity" ; + numOfLines +"''>& nbsp& nbsp" ;;

d.innerHTML + ="< input type =''text''name =''itemCode" + numOfLines +"''onkeydown =''if(event.keyCode == 9){generateRow();}''>< BR>" ;

var felement = eval(" document.forms [0] .quantity" + numOfLines);

felement.focus();

numOfLines + = 1;

}


< / script>

< / head>

< body>

< form>


数量& nbsp& nbsp ItemCode< br>

< ; input type = text name =" quantity1" >

< input type =" text"命名= QUOT; itemcode1" onkeydown =" if(event.keyCode == 9){generateRow();}">


< div id =" div">< / div> ;

< / form>

< body>

< / html>

Hi,

I wrote the code to generate a new row each time when i press tab in the
second text box in a row of two text boxes. It''s working fine. But my problem is
in the new row that is created when i press tab, the cursor should be in the first
text box. I wrote the code for that. It''s line 10 and 11.
It''s not working. Please let me know the solution.
More over when i press tab in the 2nd text box of first row the cursor is going to
second text box of second row and when i press tab from the second text box of
second row the cursor is not at all seen.
I spent a lot of time on this.


Thanks in advance.
The html file is below.


<html>
<head>
<script>
var numOfLines = 2;
function generateRow()
{
var d=document.getElementById("div");
d.innerHTML += "<input type=''text'' name=''quantity"+numOfLines+"''>&nbsp&nbsp";
d.innerHTML += "<input type=''text'' name=''itemCode"+numOfLines+"'' onkeydown=''if(event.keyCode==9){generateRow();}''>< br>" ;
var felement = eval("document.forms[0].quantity"+numOfLines);
felement.focus();
numOfLines += 1;
}

</script>
</head>
<body>
<form>

Quantity &nbsp&nbsp ItemCode<br>
<input type=text name="quantity1" >
<input type="text" name="itemcode1" onkeydown="if(event.keyCode==9) {generateRow();}">

<div id="div"></div>
</form>
<body>
</html>

推荐答案

看看...尽量避免覆盖浏览器的默认行为...


尝试在generateRow函数的末尾添加onle行...

然后检查出来


返回false;


实际上有时我也无法停止浏览器的默认行为。

返回false表示停止浏览器的默认行为


提前欢迎
look... try to avoid overriding the default behaviour of browser ...

try to add onle line at the end of the generateRow function ...
then check it out

return false;

actually sometimes i also fail to stop default behaviour of the browser.
return false means stop the default behaviour of the browser


welcome in advance


您好,


我添加了

返回false;

到上面的代码。它适用于第二行,但不适用于第三行。
Hi,

I added
return false;
to the above code. It works for the 2nd line, but not for the 3rd line onwards.


这应该不需要javascript论坛中的帮助查找帮助。
hi this should need no javascript look for help in html forum for tabindex.


这篇关于将光标聚焦到每行的第一个文本框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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