doukengzi3517 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() {
                                $(function(){
                                    var items="";
                                    $.getJSON("check-events.php",function(data){
                                    $.each(data,function(index,item) 
                                    {
                                    items+="<li><a href="+item.col1+"?eventid="+item.id+">"+item.col2+"<p></p><p>"+item.col3+"</p></li>";
                                     });






                                    $("#contacts").append(items); 
                                     $("#contacts").listview("refresh");
                                    });
                                });
                            });  
                        </script>

            <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
                </li> 
            </ul>
            </div>

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="+item.id+" 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";
            array_push($data,$row_array);

            }
        echo json_encode($data);
}

changed html

items+="<li><a href=\""+item.col1+"?eventid="+item.id+"\" 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="+item.id+"\" 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: https://stackoverflow.com/a/4158203/1178781

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 关于大棚监测的pcb板设计
  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器
  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
  • ¥15 Vue3地图和异步函数使用
  • ¥15 C++ yoloV5改写遇到的问题