Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/380.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 未正确添加listview的复选框_Javascript_Jquery_Html_Jquery Mobile_Jquery Mobile Listview - Fatal编程技术网

Javascript 未正确添加listview的复选框

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 -->

我想用image和checkbox创建一个动态列表,它工作正常,但是,当我在onload函数中动态生成它时,它不能正确生成

我的代码在下面

在本例中,HTML5中有2个li,但JavaScript中生成的第三个li无法正确生成

HTML代码:

<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');