Javascript 未正确添加listview的复选框
我想用image和checkbox创建一个动态列表,它工作正常,但是,当我在onload函数中动态生成它时,它不能正确生成 我的代码在下面 在本例中,HTML5中有2个li,但JavaScript中生成的第三个li无法正确生成 HTML代码:Javascript 未正确添加listview的复选框,javascript,jquery,html,jquery-mobile,jquery-mobile-listview,Javascript,Jquery,Html,Jquery Mobile,Jquery Mobile Listview,我想用image和checkbox创建一个动态列表,它工作正常,但是,当我在onload函数中动态生成它时,它不能正确生成 我的代码在下面 在本例中,HTML5中有2个li,但JavaScript中生成的第三个li无法正确生成 HTML代码: <body> <!-- page --> <div id="tryhtml" data-role="page" data-palette=""> <!-- header -->
<body>
<!-- page -->
<div id="tryhtml" data-role="page" data-palette="">
<!-- header -->
<div data-role="header" data-position="fixed">
<h1>Application</h1>
</div><!-- /header -->
<div data-role="content">
<ul data-icon="none" id="FB" data-role="listview" data-inset="true" data-theme="c" data-dividertheme="a">
<li data-role="list-divider">Overview</li>
<li>
<input type="checkbox" name="checkbox-1a" id="checkbox-1a" class="custom" data-iconpos="right"/>
<label for="checkbox-1a"><img src="https://fbcdn-profile-a.akamaihd.net/hprofile-ak-ash4/261025_100001129460073_937883521_q.jpg" style="margin-right:20PX; float:left" width="35" height="35"/>Cheetos dffaf</label>
</li>
<li>
<input type="checkbox" name="checkbox-2a" id="checkbox-2a" class="custom" data-iconpos="right"/>
<label for="checkbox-2a"><img src="https://fbcdn-profile-a.akamaihd.net/hprofile-ak-ash4/261025_100001129460073_937883521_q.jpg" style="margin-right:20PX; float:left" width="35" height="35"/>Cheetos dffaf</label>
</li>
</ul>
</div>
</div><!-- /page -->
</body>
应用
- 概述
-
奇托斯dffaf
-
奇托斯dffaf
js文件的Onload函数:
var tag = '<li><input type="checkbox" name="checkbox-5a" id="checkbox-5a" data-iconpos="right"/><label for="checkbox-5a"><img src="https://fbcdn-profile-a.akamaihd.net/hprofile-ak-ash4/261025_100001129460073_937883521_q.jpg" style="margin-right:20PX; float:left" width="35" height="35"/>Roy dffaf</label></li>';
$('#FB').append(tag);
$('#FB').listview('refresh');
var tag='Roy-dffaf ;
$('#FB')。追加(标记);
$('#FB')。列表视图('刷新');
工作示例:
var tag='Roy-dffaf ;
$('#FB')。追加(标记);
$('#FB').find('#checkbox-5a').checkboxradio().checkboxradio(“刷新”);
$('#FB')。列表视图('刷新');
在您的情况下,.listview('refresh')代码>
将只设置listview和listview的样式,不要忘记您还有一个复选框要设置样式。由于jquerymobile的工作方式,您首先要设置checkbox的样式,然后是listview
复选框的样式通常为。checkboxradio(“刷新”)代码>
但在本例中,我们有一个动态创建的复选框,因此首先需要使用.checkboxradio()
对其进行初始化
var tag = '<li><input type="checkbox" name="checkbox-5a" id="checkbox-5a" data-iconpos="right"/><label for="checkbox-5a"><img src="https://fbcdn-profile-a.akamaihd.net/hprofile-ak-ash4/261025_100001129460073_937883521_q.jpg" style="margin-right:20PX; float:left" width="35" height="35"/>Roy dffaf</label></li>';
$('#FB').append(tag);
$('#FB').find('#checkbox-5a').checkboxradio().checkboxradio( "refresh" );
$('#FB').listview('refresh');