2013-04-18 16:41
浏览 53

如何使用jquery mobile将页面幻灯片添加到动态创建的列表中?

Here is my html for my populated listview. I have the link grabbed from the php script aswell. Where would i put the page slide function on click event. It wont allow me to but html in the script

   <div data-role="content">
<script type="text/javascript">
                            $(document).on("pagebeforeshow", "#index1", function() {
                                    var items="";
                                    items+="<li><a href="+item.col1+"?eventid="">"+item.col2+"<p></p><p>"+item.col3+"</p></li>";


            <div data-role="fieldcontain">
                        <ul id="contacts" data-role="listview" data-divider-theme="b" data-inset="true">
                     <li data-role="list-divider" role="heading">
                 List view

Where would i add this piece this code. It keeps producing an error when i add it like this

items+="<li><a href="+item.col1+"?eventid="" data-transition="slide">"+item.col2+"<p></p><p>"+item.col3+"</p></li>";

Any ideas

Working solution php

$data = array();
        while($rowa = mysql_fetch_array($a, MYSQL_ASSOC)) 
            $row_array['id'] = $rowa['eventid'];
            $row_array['col1'] = "index.html";
            $row_array['col2'] = $rowa['eventname'];
            $row_array['col3'] = date("D jS F Y",strtotime($rowa[enddate]));
            $row_array['col4'] = "slide";

        echo json_encode($data);

changed html

items+="<li><a href=\""+item.col1+"?eventid=""\" data-transition=\""+item.col4+"\">"+item.col2+"<p></p><p>"+item.col3+"</p></li>";});
  • 写回答
  • 好问题 提建议
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • dongzhila3786 2013-04-18 16:45

    You need to escape your quotes when putting in the variables (\")

    items+="<li><a href=\""+item.col1+"?eventid=""\" data-transition=\""slide"\">"+item.col2+"<p></p><p>"+item.col3+"</p></li>";

    But, on a side note, you should be letting JQuery create your elements for you. See:

    解决 无用
    打赏 举报

相关推荐 更多相似问题