jquery动态加载表添加超链接ajax

慕尼黑3864816
浏览 2782回答 3
3回答

慕尼黑3864816

<script type="text/javascript">     function getData(){         $.ajax({             type: "get",             url: "json/data.json",             data: {             },             success: function( result ) {                 var asd=result.data;                 var len=asd.length;                 console.log(len);               if(len > 0){                   for(var i=0; i<len; i++) {                       console.log(asd[i]);                       var len2 = asd[i].products.length;                       var prd=asd[i].products;                       console.log(len2);                       if (len2 == 0) {                       } else {                           for (var j = 0; len2 > j; j++) {                               console.log(prd[j]);                               var tr = document.createElement('tr');                               var thid = document.createElement('th');                               $(thid).attr("rowspan", len2);                               var tdname = document.createElement('td');                               $(tdname).attr("rowspan", len2);                               var tdurl = document.createElement('td');                               var a=document.createElement('a');                               var tdbackUrl = document.createElement('td');                               var tdserverName = document.createElement('td');                               var tddesc = document.createElement('td');                               var tdusername = document.createElement('td');                               var tdpassword = document.createElement('td');                               thid.innerHTML = asd[i].id;                               tdname.innerHTML = asd[i].name;                               a.innerHTML=prd[j].url;                               tdserverName.innerHTML = prd[j].serverName;                               //tdurl.innerHTML = prd[j].url;                               tdbackUrl.innerHTML = prd[j].backUrl;                               tddesc.innerHTML = prd[j].desc;                               tdusername.innerHTML = prd[j].username;                               tdpassword.innerHTML = prd[j].password;                               if (j == 0) {                                   tr.appendChild(thid);                               }                               if (j == 0) {                                   tr.appendChild(tdname);                               }                               tdurl.appendChild(a);                               tr.appendChild(tdserverName);                               tr.appendChild(tdurl);                               tr.appendChild(tdbackUrl);                               tr.appendChild(tddesc);                               tr.appendChild(tdusername);                               tr.appendChild(tdpassword);                               var tbody = document.getElementById('tbody');                               tbody.appendChild(tr);                           }                       }                }               }             }         })        }; </script>

慕尼黑3864816

我用ajax获取了json的数据,然后给json数据里的网址添加超链接,这些都是动态加载的

qq_黑泽明_0

说详细点?
打开App,查看更多内容
随时随地看视频慕课网APP