我必須動態創建單選按鈕組。我能夠成功創建它。但問題是動態創建的單選按鈕看起來不像靜態按鈕。樣式不能在動態創建的單選按鈕中正確應用
我嘗試兩種方法: 1)上fieldset
調用create
- ui-corner-all
類在內跨度並且作爲結果的所有無線電按鈕出現舍入被獲取添加。 2)在fieldset
的div上調用create
- 這裏問題比較好。但是仍然存在一些問題。首先,當只有單選按鈕時,ui-controlgroup-last
類被添加到該單選按鈕。接下來,當第二個單選按鈕被添加時,ui-controlgroup-last
類正在被添加到該單選按鈕。但ui-controlgroup-last
仍然存在於第一個單選按鈕中,並且此循環重複。因此,所有單選按鈕都具有最後單選按鈕的樣式。
這是我的代碼:
<!DOCTYPE html>
<html lang="en">
<head>
<link rel="stylesheet" href="http://code.jquery.com/mobile/1.0rc1/jquery.mobile-1.0rc1.min.css" />
<script src="http://code.jquery.com/jquery-1.6.4.min.js"></script>
<script src="http://code.jquery.com/mobile/1.0rc1/jquery.mobile-1.0rc1.min.js"></script>
<script>
$(document).ready(function()
{
for (var i = 0; i < 3; i++)
{
$("#rgroup1").append('<input type="radio" name="rg1" id="radio1-'+i+'"/><label for="radio1-'+i+'">Value</label>');
$("#rgroup1").trigger("create");
$("#rgroup2").append('<input type="radio" name="rg2" id="radio2-'+i+'"/><label for="radio2-'+i+'">Value</label>');
$("#radiodiv1").trigger("create");
}
});
</script>
</head>
<body>
<div data-role="content">
<h3>Normal radio buttons</h3>
<div id="radiodiv">
<fieldset data-role="controlgroup" id="rgroup">
<input type="radio" name="rg" id="radio-1"/><label for="radio-1">Value</label>
<input type="radio" name="rg" id="radio-2"/><label for="radio-2">Value</label>
<input type="radio" name="rg" id="radio-3"/><label for="radio-3">Value</label>
</fieldset>
</div>
<h3>Dynamically created-Div Refresh</h3>
<div id="radiodiv">
<fieldset data-role="controlgroup" id="rgroup1">
</fieldset>
</div>
<h3>Dynamically created-Fieldset Refresh</h3>
<div id="radiodiv1">
<fieldset data-role="controlgroup" id="rgroup2">
</fieldset>
</div>
</div>
</body>
PS - 爲什麼我呼籲每個之後創建的原因追加是因爲多數民衆贊成它是如何工作的我的實際用例,只有一個單選按鈕在創建任何時候。
生成的源
<html lang="en" class="ui-mobile"><head><base href="http://localhost:8081/html5/calendar-new/radio_issue.html">
<link rel="stylesheet" href="http://code.jquery.com/mobile/1.0rc1/jquery.mobile-1.0rc1.min.css">
<script src="http://code.jquery.com/jquery-1.6.4.min.js"></script>
<script src="http://code.jquery.com/mobile/1.0rc1/jquery.mobile-1.0rc1.min.js"></script>
<script>
$(document).ready(function()
{
for (var i = 0; i < 3; i++)
{
$("#rgroup1").append('<input type="radio" name="rg1" id="radio1-'+i+'"/><label for="radio1-'+i+'">Value</label>');
$("#rgroup1").trigger("create");
$("#rgroup2").append('<input type="radio" name="rg2" id="radio2-'+i+'"/><label for="radio2-'+i+'">Value</label>');
$("#radiodiv1").trigger("create");
}
});
</script>
<title></title></head>
<body class="ui-mobile-viewport"><div data-role="page" data-url="/html5/calendar-new/radio_issue.html" tabindex="0" class="ui-page ui-body-c ui-page-active" style="min-height: 933px; ">
<div data-role="content" class="ui-content" role="main">
<h3>Normal radio buttons</h3>
<div id="radiodiv">
<fieldset data-role="controlgroup" id="rgroup" class="ui-corner-all ui-controlgroup ui-controlgroup-vertical">
<div class="ui-radio"><input type="radio" name="rg" id="radio-1"><label for="radio-1" data-theme="c" class="ui-btn ui-btn-icon-left ui-radio-off ui-corner-top ui-btn-up-c"><span class="ui-btn-inner ui-corner-top"><span class="ui-btn-text">Value</span><span class="ui-icon ui-icon-radio-off ui-icon-shadow"></span></span></label></div>
<div class="ui-radio"><input type="radio" name="rg" id="radio-2"><label for="radio-2" data-theme="c" class="ui-btn ui-btn-icon-left ui-radio-off ui-btn-up-c"><span class="ui-btn-inner"><span class="ui-btn-text">Value</span><span class="ui-icon ui-icon-radio-off ui-icon-shadow"></span></span></label></div>
<div class="ui-radio"><input type="radio" name="rg" id="radio-3"><label for="radio-3" data-theme="c" class="ui-btn ui-btn-icon-left ui-radio-off ui-corner-bottom ui-controlgroup-last ui-btn-up-c"><span class="ui-btn-inner ui-corner-bottom ui-controlgroup-last"><span class="ui-btn-text">Value</span><span class="ui-icon ui-icon-radio-off ui-icon-shadow"></span></span></label></div>
</fieldset>
</div>
<h3>Dynamically created-Div Refresh</h3>
<div id="radiodiv">
<fieldset data-role="controlgroup" id="rgroup1" class="ui-corner-all ui-controlgroup ui-controlgroup-vertical">
<div class="ui-radio"><input type="radio" name="rg1" id="radio1-0"><label for="radio1-0" data-theme="c" class="ui-btn ui-btn-icon-left ui-btn-corner-all ui-radio-off ui-btn-up-c"><span class="ui-btn-inner ui-btn-corner-all"><span class="ui-btn-text">Value</span><span class="ui-icon ui-icon-radio-off ui-icon-shadow"></span></span></label></div><div class="ui-radio"><input type="radio" name="rg1" id="radio1-1"><label for="radio1-1" data-theme="c" class="ui-btn ui-btn-icon-left ui-btn-corner-all ui-radio-off ui-btn-up-c"><span class="ui-btn-inner ui-btn-corner-all"><span class="ui-btn-text">Value</span><span class="ui-icon ui-icon-radio-off ui-icon-shadow"></span></span></label></div><div class="ui-radio"><input type="radio" name="rg1" id="radio1-2"><label for="radio1-2" data-theme="c" class="ui-btn ui-btn-icon-left ui-btn-corner-all ui-radio-off ui-btn-up-c"><span class="ui-btn-inner ui-btn-corner-all"><span class="ui-btn-text">Value</span><span class="ui-icon ui-icon-radio-off ui-icon-shadow"></span></span></label></div></fieldset>
</div>
<h3>Dynamically created-Fieldset Refresh</h3>
<div id="radiodiv1">
<fieldset data-role="controlgroup" id="rgroup2" class="ui-corner-all ui-controlgroup ui-controlgroup-vertical">
<div class="ui-radio"><input type="radio" name="rg2" id="radio2-0"><label for="radio2-0" data-theme="c" class="ui-btn ui-btn-icon-left ui-radio-off ui-corner-top ui-corner-bottom ui-controlgroup-last ui-btn-up-c"><span class="ui-btn-inner ui-corner-top ui-corner-bottom ui-controlgroup-last"><span class="ui-btn-text">Value</span><span class="ui-icon ui-icon-radio-off ui-icon-shadow"></span></span></label></div><div class="ui-radio"><input type="radio" name="rg2" id="radio2-1"><label for="radio2-1" data-theme="c" class="ui-btn ui-btn-icon-left ui-radio-off ui-corner-bottom ui-controlgroup-last ui-btn-up-c"><span class="ui-btn-inner ui-corner-bottom ui-controlgroup-last"><span class="ui-btn-text">Value</span><span class="ui-icon ui-icon-radio-off ui-icon-shadow"></span></span></label></div><div class="ui-radio"><input type="radio" name="rg2" id="radio2-2"><label for="radio2-2" data-theme="c" class="ui-btn ui-btn-icon-left ui-radio-off ui-corner-bottom ui-controlgroup-last ui-btn-up-c"><span class="ui-btn-inner ui-corner-bottom ui-controlgroup-last"><span class="ui-btn-text">Value</span><span class="ui-icon ui-icon-radio-off ui-icon-shadow"></span></span></label></div></fieldset>
</div>
</div>
</div><div class="ui-loader ui-body-a ui-corner-all" style="top: 290px; "><span class="ui-icon ui-icon-loading spin"></span><h1>loading</h1></div></body></html>
可否請您上傳渲染您在瀏覽器中查看的HTML –