js如何动态创建一个新的标签

  

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
        var DS;
            DS = CallIVRAjaxClass.GetBranchCallCount().value;
            var obj = {};
            obj.branch = "_branch";
            obj.count = "_count";
            if (DS != null && typeof (DS) == "object" && DS.Tables != null) {
                if (DS.Tables[0].Rows.length > 0) {
                    for (var i = 0; i < DS.Tables[0].Rows.length; i++) {
 
                        var MapDiv = document.getElementById("MapDiv");
                        var MapImg = document.createElement("img");//开始创建一个img标签
                        MapImg.name = "imgMap";//开始赋值一些必要属性,其中alt和src必须要有
                        MapImg.alt = "";
                        MapImg.src = "";
                        MapImg.style.position = "absolute";//由于我是用于图片叠加,所以用了绝对定位,
                        MapDiv.appendChild(MapImg);//将这个创建好的追加到div容器里面
 
 
 
                        var _count = DS.Tables[0].Rows[i][obj.count];  //去处当前obj.count值的数据
                        var ImagePath = "image/" + DS.Tables[0].Rows[i][obj.branch] + "_";    //提前设置好路径和图片前半部分的名字
                        var _Map = document.getElementsByName("imgMap")[i];   //根绝name值找到当前img标签
<br>              //下面判断当前取出来的值来确定图片。注:png格式才可以有透明属性
                        var str = "";
                        if (_count == 0) {
                            //_Map.src = ImagePath +
                            str = i + ".png";
                        } else if (_count >= 1 && _count <= 5) {
 
                            str = i + ".png";
 
                        } else if (_count >= 6 && _count <= 10) {
                            str = i + ".png";
 
 
                        } else if (_count >= 11 && _count <= 20) {
                            str = i + ".png";
 
                        } else if (_count >= 21 && _count <= 30) {
                            str = i + ".png";
 
 
                        } else {
                            str = i + ".png";
 
                        }
 
//                        //测试留
//                        str = "";
 
                        _Map.src = ImagePath + str;//循环给img标签src属性值,由于我要放的图片是部分透明的,所有叠加在一起是刚刚好
                    }
                }
            }

  

js如何动态创建一个新的标签,布布扣,bubuko.com

js如何动态创建一个新的标签

上一篇:jQuery编程的最佳实践


下一篇:tensorflow-gpu版linux端安装成功检验