为了账号安全,请及时绑定邮箱和手机立即绑定

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

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

查看完整描述

3 回答

?
慕尼黑3864816

TA贡献3条经验 获得超0个赞

<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>


查看完整回答
反对 回复 2017-04-05
?
慕尼黑3864816

TA贡献3条经验 获得超0个赞

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


查看完整回答
反对 回复 2017-04-05
?
qq_黑泽明_0

TA贡献23条经验 获得超3个赞

说详细点?
查看完整回答
反对 回复 2017-03-31
  • 3 回答
  • 1 关注
  • 2772 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信