创建动态弹出窗口

时间:2015-05-19 09:51:30

标签: javascript jquery html json

JS

 $(function () {
     var dmJSON = "clues.json";
     $.getJSON(dmJSON, function (data) {
         var idx = 1;
         $.each(data.details, function (i, f) {
             var myid = 'mypop' + String(idx);
             idx++;
             var $popup = "<popup id='" + myid + "' class='mystyles1'><tr>" + "<p>" + f.Myclue + "</p></tr>" + "<tr><p>" + f.Description + "</p></tr>" + "<tr><p>" + f.Updates + "</p></tr>" + "<tr><p> " + f.Users + "</p></tr>" + "&nbsp;&nbsp;&nbsp;</popup>"
             $("#popup-container").append($popup)

         });

     });
 });

我想创建动态弹出窗口并显示来自动态表的json文件的数据。使用上面的代码,弹出窗口显示整个json数据,而我希望显示特定数据。任何解决方案都会有所帮助。提前致谢

1 个答案:

答案 0 :(得分:0)

使用for循环:

$(function () {
     var dmJSON = "clues.json";
     $.getJSON(dmJSON, function (data) {
         var idx = 1;
     for (var i =0; i < data.details.length; i++) {
         var myid = 'mypop' + String(idx);
         idx++;
         var $popup += "<popup id='" + myid + "' class='mystyles1'><tr>" + "<p>" + data.details[i].Myclue + "</p></tr>" + "<tr><p>" + data.details[i].Description + "</p></tr>" + "<tr><p>" + data.details[i].Updates + "</p></tr>" + "<tr><p> " + data.details[i].Users + "</p></tr>" + "&nbsp;&nbsp;&nbsp;</popup>"

     }
     $("#popup-container").append($popup);

     });
 });