jQuery焦点功能在Firefox中不起作用 [英] jQuery focus function not working in Firefox

查看:103
本文介绍了jQuery焦点功能在Firefox中不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

下面的代码段在单击链接后将重点放在文本输入上.它适用于Chrome 2.x,IE8和Opera 9.64,但不适用于Firefox 3.0.9.文本输入在Firefox中快速闪烁,然后消失,我目前在Windows XP SP2上工作.

The following piece of code focuses the text input after you click on the link. It works fine for Chrome 2.x, IE8 and Opera 9.64 but not on Firefox 3.0.9. The text input flashes quickly in Firefox then disappears, I'm currently working on Windows XP SP2.

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3/jquery.min.js"></script> 
<script>
$(document).ready(function()
{
    $("a").click(function() {
        var field_id = $(this).attr("href");
        $(field_id).focus();
    });
});
</script>

<a href="#text_field">Focus</a>
<input type="text" name="text_field" id="text_field" />

有人知道如何在Firefox中处理上述问题吗?

Does anyone know how to handle the above in Firefox?

推荐答案

我不知道这是不是您想要的.要专注于输入,请点击标签,您可以执行以下操作:

I don't know if is this you want. To put focus on the input clicking on the label you can do this:

<label for="text_field">Label</label>
<input type="text" name="text_field" id="text_field" />

OR

<label>Label
<input type="text" name="text_field" id="text_field" />
</label>

这篇关于jQuery焦点功能在Firefox中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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