chrome/ff 和 jquery 中的 TabIndex 属性不能一起工作?
我正在使用 jquery 1.6 并希望在我的 iframe 中执行此代码:
$(document).bind('keydown', function (e) {
if (e.which == 9) {
var tabbie = $(e.target).attr('tabIndex');
if (tabbie) {
var el = $("*[tabIndex='" + (parseInt(tabbie) + 1) + "'");
if (el.length) {
// do standard action
}
else {
e.preventDefault();
window.top.focus();
return false;
}
}
}
});
如您所见,它应该执行以下操作: 在 tab 键按下时,查看是否存在具有下一个 tabindex 值的元素。如果是这样,一切都好,让浏览器去吧。如果不存在,则将焦点授予 iframe 的父级。
这在 IE8 中有效,但在 chrome/FF 中则不然:即使 html 有 tabindexes,你也无法选择任何内容:
<div class="row fl-controls-left">
<input id="username" name="username" tabindex="1" type="text" value="" size="25" autocomplete="false"/>
</div>
<div class="row fl-controls-left last">
<input id="password" name="password" tabindex="2" type="password" value="" size="25" autocomplete="off"/>
</div>
<div class="actions rounded-bottom">
<a href="javascript:void(window.top.location.href = 'http://localhost/')" tabindex="4">Forgot?</a>
<div class="row btn-row">
<input name="submit" value="Aanmelden" tabindex="3" type="submit" />
<input name="reset" value="leegmaken" tabindex="1000" type="reset" />
</div>
</div>
有人知道为什么吗?
(为什么我需要这段代码?回答我的其他问题 Tabindex 跳过 iframe但里面没有内容)
干杯!
I'm using jquery 1.6 and want to execute this code in my iframe:
$(document).bind('keydown', function (e) {
if (e.which == 9) {
var tabbie = $(e.target).attr('tabIndex');
if (tabbie) {
var el = $("*[tabIndex='" + (parseInt(tabbie) + 1) + "'");
if (el.length) {
// do standard action
}
else {
e.preventDefault();
window.top.focus();
return false;
}
}
}
});
As you can see, what it should do:
On tab-keypress, see if there is an element with a next tabindex value. If so, all is good, let the browser go to it. If there isn't, then give focus to the parent of the iframe.
This works in IE8, but in chrome/FF it doesn't: you cannot tab anything, even though the html has tabindexes:
<div class="row fl-controls-left">
<input id="username" name="username" tabindex="1" type="text" value="" size="25" autocomplete="false"/>
</div>
<div class="row fl-controls-left last">
<input id="password" name="password" tabindex="2" type="password" value="" size="25" autocomplete="off"/>
</div>
<div class="actions rounded-bottom">
<a href="javascript:void(window.top.location.href = 'http://localhost/')" tabindex="4">Forgot?</a>
<div class="row btn-row">
<input name="submit" value="Aanmelden" tabindex="3" type="submit" />
<input name="reset" value="leegmaken" tabindex="1000" type="reset" />
</div>
</div>
Anyone know why?
(Why I want this code? To answer my other question Tabindex to skip iframe but not content inside)
Cheers!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论