Firefox错误地记住单选按钮 [英] Firefox remembering radio buttons incorrectly

查看:178
本文介绍了Firefox错误地记住单选按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Firefox 7.0.1中,我有两个复选框和一些其他的输入。

当我通过jQuery添加另一个输入时,Firefox不能正确记住什么是无线电输入例如,如果我选择第一个单选按钮,然后刷新页面,第二个单选按钮被选中,而不是第一个,如果我再次刷新没有收音机按钮被选中。

您应该能够将下面的代码复制并粘贴到一个新的文件中进行测试:

 <!DOCTYPE html> 
< html lang =en>
< head>
< meta content =text / html; charset = utf-8http-equiv =Content-Type/>
< script src =https://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js>< / script>
< script> ('< input class =selecttype =textname =new_text_input/>)之后的
$(document).ready(function(){
$('select')。 ');
});
< / script>
< title> Pretty jQuery Form< / title>
< / head>
< body>
< form>
< fieldset>
< label>选择框< / label>
< select name =my_select>
< option>选项1< / option>
< option>选项2< / option>
< option>选项3< / option>
< option>选项4< / option>
< / select>
< / fieldset>
< fieldset>
< label>文字输入< / label>
< input class =textid =text_inputname =inputtype =text/>
< / fieldset>
< fieldset>
< label>文字区域< / label>
< textarea>< / textarea>
< / fieldset>
< fieldset>
< label>收音机< / label>
< input value =1name =radioid =radio1type =radio/> < label for =radio1> Radio 1< / label>
< input value =2name =radioid =radio2type =radio/> < label for =radio2> Radio 2< / label>
< / fieldset>
< / form>
< / body>
< / html>

我应该注意的是,我实际上想要做的事情更复杂,但是经过几个小时的调试我已经设法缩小到这个范围。

解决方案

有一篇关于这个问题的文章: http://www.ryancramer.com/journal/entries/radio_buttons_firefox/



这个错误最早在五年前被报告: https://bugzilla.mozilla。 org / show_bug.cgi?id = 394782



解决方案:

 < form autocomplete =off> 

或者使用jQuery:

}); 

也可以通过在radio按钮上加上autocomplete =off (这样,您仍然可以为其他表单字段自动填充)。


In Firefox 7.0.1, I have two checkboxes and a number of other inputs.

When I add another input via jQuery Firefox does not correctly remember what radio inputs are selected.

For instance, if I select the first radio button and then refresh the page the second radio button is selected rather than the first and if I refresh again no radio button is selected.

You should be able to copy and paste the code below into a new file to test for yourselves:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta content="text/html; charset=utf-8" http-equiv="Content-Type"/>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js"></script>
    <script>
    $(document).ready(function(){
    $('select').after('<input class="select" type="text" name="new_text_input" />');
});
    </script>
    <title>Pretty jQuery Form</title>
</head>
<body>
<form>
    <fieldset>
        <label>Select Box</label>
        <select name="my_select">
            <option>Option 1</option>
            <option>Option 2</option>
            <option>Option 3</option>
            <option>Option 4</option>
        </select>
    </fieldset>
    <fieldset>
        <label>Text Input</label>
        <input class="text" id="text_input" name="input" type="text" />
    </fieldset>
    <fieldset>
        <label>Text Area</label>
        <textarea></textarea>
    </fieldset>
    <fieldset>
        <label>Radio</label>
        <input value="1" name="radio" id="radio1" type="radio" /> <label for="radio1">Radio 1</label>
        <input value="2" name="radio" id="radio2" type="radio" /> <label for="radio2">Radio 2</label>
    </fieldset>
</form>
</body>
</html>

I should note that what i'm actually trying to do is more complicated but after many hours of debugging i've managed to narrow it down to this.

解决方案

There is an article about this issue: http://www.ryancramer.com/journal/entries/radio_buttons_firefox/

The bug was first reported five years ago: https://bugzilla.mozilla.org/show_bug.cgi?id=394782

Solution:

<form autocomplete="off">

Or using jQuery:

$(document).ready(function() {
    if ($.browser.mozilla) $("form").attr("autocomplete", "off");   
}); 

It is also possible to prevent the problem by just putting autocomplete="off" on the radio buttons themselves (this way you can still get autocomplete for the other form fields).

这篇关于Firefox错误地记住单选按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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