Radio Button and CheckBox在FireFox中刷新自动改变选中项

今天开发过程中出现了这样一个问题,我选中radio button list中的一项,然后F5刷新页面,FireFox浏览器会自动上移选中项。太奇怪了!

 

情况,我在页面中有一个

<div id="dialog-add-form-perfile" title="<%: com.nowdocs.nowsource.Admin.Resources.GroupBuyer.AddUserTypeTitle%>"style="display: none;">
    <div id="CurrentGroupUserTypesPer">
        <% Html.RenderPartial("AddUserTypePanel"); %>
    </div>
</div>

 注意当有2个时候,自动上移2个,以此类推。

 

郁闷死我了,我找了好久才找到,是因为这个引起的。

 

在网上找到,原来是因为FireFox的一个bug产生的。

http://www.whypad.com/posts/firefox-radio-button-bug/559/

(这是看到发生的样子)

 

以下是解决方案:

<html>
<head>
	<title>Firefox Autocomplete Test</title>
	<script type="text/javascript" src="jquery.js"></script>
	<script type="text/javascript">
		$(document).ready(function() {
                        //这句话很重要!!!
			if($.browser.mozilla) $("form").attr("autocomplete", "off"); 	
			$("#test").after("<input type='text' name='test2' value='Test 2' />"); 
		}); 
	</script>
</head>
<body>
	<h1>Reload this page, radio buttons don't change</h1>
	<p>Adding autocomplete="off" to the form tag fixes the issue. But "autocomplete" is not a valid XHTML attribute, so you may want to do this from jQuery/javascript. View the source of this page to see how.</p>

	<form method="post">
		<input type="text" id="test" name="test1" value="Test" />

		<label><input type="radio" name="radiotest" value="1" checked="checked" /> 1</label>
		<label><input type="radio" name="radiotest" value="2" /> 2</label>
		<label><input type="radio" name="radiotest" value="3" /> 3</label>

	</form>
</body>
</html>

你可能感兴趣的:(JavaScript,html,jquery,firefox)