Radio buttons being reset in FF on cache-refresh
(This is technically an addendum to an earlier StackOverflow question I had posted, but my original post asked a different question which doesn't really cover this topic -- I don't want to edit my older question as I feel this is different enough to merit its own page)
While browsing my website in Firefox 3.5 (and only FF3.5), I come across a page with two radio buttons that have the following HTML code:
<input id="check1" type="radio" value="True" name="check" checked="checked"开发者_高级运维;/>
<input id="check2" type="radio" value="False" name="check"/>
This page renders as expected, with 'check1' checked and 'check2' unchecked. When I then go to refresh the page by pressing Control + R, the two radio buttons render, but they are both unchecked even though the raw HTML code is the same (as above). If I do a cache-miss refresh (via Control + F5 or Control + Shift + R), the page returns back to the way you'd expect it.
This is not a problem in any other browser I've tried except FF3.5.
What is causing these radio buttons to be reset on a normal refresh? How can I avoid this?
Turns out it's a bug in Firefox.
I used this to force firefox to reset the radiobuttons checked upon refresh.
$(function(){ $('input[name="radiobuttongroup"]')[0].checked = true; });
Solution:
<form autocomplete="off">
Or using jQuery:
$(document).ready(function() {
if ($.browser.mozilla) $("form").attr("autocomplete", "off");
});
We've had a similar bug in firefox when using jquery to change the selection. Even though the code changed correctly according to firebug none of the radio buttons was selected. The solution we found is to remove the radio buttons from the DOM and just put them back.
var allradiobuttons = $('...');
allradiobuttons.click(function() {
var radiobutton = $(this);
allradiobuttons.removeAttr("checked");
radiobutton.attr("checked", "checked");
var parent = radiobutton.parent();
parent.html(parent.html()); // This is a weird fix
}
精彩评论