HTML / JS:追加不起作用

时间:2013-11-08 03:08:14

标签: javascript jquery html

我想动态地将表/列表附加到HTML页面。我的代码如下:

    <!doctype html>
    <html>
        <head>
            <meta charset="utf-8">
            <meta name="viewport" content="width=device-width,initial-scale=1">
            <title>Lead Manager</title>
            <link rel="stylesheet" href="themes/Bootstrap.css">
            <link rel="stylesheet" href="themes/jquery.mobile.structure-1.2.0.min.css" />
            <script src="themes/jquery-1.8.2.min.js"></script>
            <script src="themes/jquery.mobile-1.2.0.min.js"></script>
            </head>
        <body id="body" name="body">
           <div data-role="page" data-theme="a">
            <div data-role="header" data-position="inline">
                <h1>Lead Manager</h1>
            </div>
            <div data-role="content" data-theme="a">
                <h2>List of Leads</h2>          
            </div>
           </div>

        </body>             

     <script>
        $(document).ready(function(e) { 
            //var data = Android.getLeads();
            var data = [{"status":"1","name":"1","campaign":"1","date":"1"},{"status":"2","name":"2","campaign":"2","date":"2"}];
            var items = [];
            var date;
            var name;
            var status;
            //eval(" var x = " + data + " ; ");         
            //var y = JSON.stringify(x);                        
            $.each(data, function(key,val){
                items.push('<tr><td>' + val.date + '</tr></td>');   
            });                         
            var text = $('<table/>', { html: items.join('')});
            $('<table/>', {     
                html: items.join('')
                }).appendTo('body');                        
          });         
       </script>
</html>

Items []变量正在填充tr和td值。但是,appendTo,不起作用。您可以看到JSON不需要eval,因为它已经具有所需的格式。

请帮忙吗?

1 个答案:

答案 0 :(得分:0)

问题主要是因为jquery.mobile脚本,因为它不允许动态添加html代码。