简体   繁体   English

Chrome中的元素错误

[英]Wrong element focused in Chrome

In my javascript web application I've a table with custom cells, with read mode (Simple label) and edit mode on double-click (input). 在我的javascript Web应用程序中,我有一个带有自定义单元格的表,具有双击(输入)时的读取模式(简单标签)和编辑模式。 When I'm in edit mode, the focus is setted on the div that contains the input (in td) and then I can use TAB to move to another cell. 当我处于编辑模式时,将焦点设置在包含输入的div上(以td表示),然后可以使用TAB移至另一个单元格。 When I'm in read mode, the focus is setted ever on the div that contains the label and I can use TAB and Arrows to move to another cell. 当我处于读取模式时,焦点将一直设置在包含标签的div上,并且我可以使用TAB和Arrows移至另一个单元格。 This works perfect in Explorer, but in Chrome, in read mode, the focus is different: is setted ever on table element and then I can't use TAB and Arrows to move to another cell.. I've tried also force focus setting an Interval: 这在Explorer中非常有效,但是在Chrome的读取模式下,焦点是不同的:将焦点设置在表格元素上,然后我不能使用TAB和Arrows移到另一个单元格。时间间隔:

$("#iddiv").focus()

The problem is just on Chrome 问题仅在Chrome上

<table>
<tbody>
<tr>
<td>
<div class='...'>
<label></label>
</div>
</td>
......
</tr>
</tbody>
</table>

Set an attribute of tabindex="0" on the <div> s (technique found in this blog post ) <div>上设置tabindex="0"的属性( 此博客文章中的技术

 $(function() { $('div[tabindex]').first().focus(); }); 
 td { outline: 1px solid grey; } td label { display: inline-block; padding: 5px; } 
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <table> <tbody> <tr> <td> <div tabindex="0"> <label>Cell 1</label> </div> </td> <td> <div tabindex="0"> <label>Cell 2</label> </div> </td> <td> <div tabindex="0"> <label>Cell 3</label> </div> </td> <td> <div tabindex="0"> <label>Cell 4</label> </div> </td> <td> <div tabindex="0"> <label>Cell 5</label> </div> </td> </tr> <tr> <td> <div tabindex="0"> <label>Cell 6</label> </div> </td> <td> <div tabindex="0"> <label>Cell 7</label> </div> </td> <td> <div tabindex="0"> <label>Cell 8</label> </div> </td> <td> <div tabindex="0"> <label>Cell 9</label> </div> </td> <td> <div tabindex="0"> <label>Cell 10</label> </div> </td> </tr> </tbody> </table> 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM