【发布时间】:2012-04-25 13:52:05
【问题描述】:
我正在使用 JQuery-UI 来显示像 here 这样的单选按钮。
我有以下 HTML 代码:
<div id="radioDiv">
<input type="radio" id="u1-radio" name="radio" value="" checked/>
<label for="u1-radio">U1</label>
<input type="radio" id="u2-radio" name="radio" value="" />
<label for="u2-radio">U2</label>
<input type="radio" id="g1-radio" name="radio" value="" />
<label for="g1-radio">G1</label>
</div>
以及以下 JavaScript:
$(document).ready(function(){
$("#radioDiv").buttonset();
getUseCase("u1");
}
function getUseCase(useCase){
if( useCase == "u1" ){
$("#u2-radio").checked = false;
$("#g1-radio").checked = false;
$("#u1-radio").checked = true;
$("#radioDiv").buttonset('refresh');
}
if( useCase == "u2" ){
$("#u1-radio").checked = false;
$("#g1-radio").checked = false;
$("#u2-radio").checked = true;
$("#radioDiv").buttonset('refresh');
}
if( useCase == "g1" ){
$("#u1-radio").checked = false;
$("#u2-radio").checked = false;
$("#g1-radio").checked = true;
$("#radioDiv").buttonset('refresh');
}
}
按钮工作正常,但问题是当我使用 F5 键刷新页面时:选中的按钮仍然是最后一个,因此“radioDiv”不会在选中第一个按钮时刷新。
我不明白为什么..刷新不应该召回$(document).ready(function(){})?
【问题讨论】:
-
你在用火狐吗?看看这个问题stackoverflow.com/q/9727117/348841
-
出于测试目的,我使用 Firefox、Chrome 和 IE,但还是感谢您的提示!
标签: jquery jquery-ui radio-button