动态创建ListView不适用于移动版的Jquery

动态创建ListView不适用于移动版的Jquery,listview,jquery-mobile,dynamically-generated,Listview,Jquery Mobile,Dynamically Generated,Jquery Mobile遇到了一个问题:我想使用JS脚本从头开始在gridView中动态创建listView 我的HTML代码是: <head> <link rel="stylesheet" href="http://code.jquery.com/mobile/1.2.0/jquery.mobile-1.2.0.min.css" /> <!--<script src="http://code.jquery.com/jquery-1.8.2.

Jquery Mobile遇到了一个问题:我想使用JS脚本从头开始在gridView中动态创建listView

我的HTML代码是:

<head>
    <link rel="stylesheet" href="http://code.jquery.com/mobile/1.2.0/jquery.mobile-1.2.0.min.css" />
    <!--<script src="http://code.jquery.com/jquery-1.8.2.min.js"></script>-->
    <script src="http://code.jquery.com/mobile/1.2.0/jquery.mobile-1.2.0.min.js"></script>   
</head>
<body>
    <div data-role="page" id="index">
        <div data-theme="b" data-role="header">
            <h1>Listview Test</h1>
        </div>
        <div data-role="content" id="pageContent">
        </div>
    </div>    
</body>
我的JS代码是:

$(document).on('pagebeforeshow', '#index', function()
{ 
    var html = "";
    html += "<div class='ui-grid-b'>";
    html += "<div class='ui-block-a' id='block_a'>"
    html += "<ul data-role='listview' data-split-icon='star' data-split-theme='a' class='listview' id='daViewList'>"

    html += "<li id='grid_li'>"
    html += "<a href='projets.html'>";
    html += "<img src='http://demos.jquerymobile.com/1.2.0-alpha.1/docs/lists/images/album-bb.jpg' />";
    html += "<h3>A</h3>";
    html += "<p>Another one</p>";
    html += "<p>And finally another one</p></a>";
    html += "<a href='simulations.html' data-transition='slide' data-icon='arrow-r' data-theme='c'></a>";
    html += "</li>";
    html += "</ul>";
    html += "</div>";
    html += "</div>";
    $(html).appendTo('#pageContent');
    $("#daViewList").listview().listview("refresh");
});
这个JSFiddle:精确地向您展示了我想要实现的目标,但是当我勾选左侧面板上的jquerymobile1.2.0选项时,代码不再有效。问题是我使用Jquery Mobile制作我的应用程序,所以我无法摆脱它

代码中似乎有什么错误?为了满足Jquery移动应用的需求,我需要做哪些更改


谢谢大家

你们应该把代码放在左面板第二个下拉列表的头部,选择“不换行”。这个很好用,谢谢。