IE失去对模态输入字段的关注 [英] IE loses focus on input field in modal

查看:107
本文介绍了IE失去对模态输入字段的关注的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个相当复杂的Web应用程序,我将其简化为以下两个HTML页面,但问题仍然存在.问题?厚框模式的(iframe)输入字段在IE(8& 9)中经过一秒钟(或更短的时间)后便失去焦点.仅当它处于模态时才会发生.如果您单独加载页面,则焦点不会丢失.

I've got a fairly complex web app which I've condensed down to the following two HTML pages, and the problem still exists. The problem? The thickbox modal's (iframe) input field loses focus after a second (or less) in IE (8 & 9). It only occurs when it's in the modal. If you load the page on its own, focus is not lost.

我已经尝试了jQuery 1.4.2和1.7.2,并且每个问题都出现了.我将其设置为jsfiddle,但认为它不支持能够触发第二页.对其进行设置,以便您可以在此处工作

I've tried both jQuery 1.4.2 and 1.7.2, and the issue occurs with each. I'd set this up as jsfiddle but don't think it supports being able to trigger a second page. Have set it up so you can see it working here

基础页:

<!DOCTYPE HTML>
<html>
<head>
<link href="http://jquery.com/demo/thickbox/thickbox-code/thickbox.css" media="screen" rel="stylesheet" type="text/css" >
</head>
<body>
<a id="createAccountLink" class="thickbox" href="test2.html?KeepThis=true&TB_iframe=true&height=400&width=600">Login</a>

<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<script type="text/javascript" src="http://jquery.com/demo/thickbox/thickbox-code/thickbox.js"></script>
</body>
</html> 

模式:

<html>
<head>
</head>
<body>
<input type="text" id="ContactFormName" name="firstName" class="text" value="" />

<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<script type="text/javascript">
$("#ContactFormName").focus();
</script>
</body>
</html>

如果我是从头开始构建的,则不会使用thickbox.但是,现在更改它并不是真正的选择,因为它已在其他地方大量使用.

If I was building this from scratch, I wouldn't use thickbox. But changing it isn't really an option right now since it's heavily used elsewhere.

答案 重点必须推迟.甚至1ms都可以.

Answer The focus has to be delayed. Even 1ms works.

setTimeout (function () {
$("#ContactFormName").focus();
}, 1);

推荐答案

必须延迟焦点.甚至1ms都可以.

The focus has to be delayed. Even 1ms works.

setTimeout (function () {
$("#ContactFormName").focus();
}, 1);

这篇关于IE失去对模态输入字段的关注的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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