您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息

JS操作图片(增,删,改) 例子_javascript技巧

2025/6/27 2:37:17发布13次查看
复制代码 代码如下:
//添加图片
            var array = ['1.jpg',
            '2.jpg',
            '3.jpg',
            '4.jpg',
            '5.jpg',
            '6.jpg',
            '7.jpg',
            '8.jpg',
            '9.jpg',
            '10.jpg',
            '11.jpg',
            '12.jpg',
            '13.jpg',
            '14.jpg',
            '15.jpg'
            ];
            //alert(array.length);
            var tablenode = document.createelement('table');
            var tbody = document.createelement('tbody');
            tablenode.setattribute('width', '600px');
            tablenode.setattribute('height', '400px');
            tablenode.setattribute('border', '2px');
            var count = 0;
            for (var i = 0; i                 var trnode = document.createelement('tr');
                for (var j = 0; j                     var tdnode = document.createelement('td');
                    var imgnode = document.createelement('img');
                    imgnode.setattribute('src', 'picture/' + array[count]);
                    tdnode.appendchild(imgnode);
                    trnode.appendchild(tdnode);
                    count++;
                }
                tbody.appendchild(trnode);
            }
            tablenode.appendchild(tbody);
            document.body.appendchild(tablenode);
        }
        //    1.将第2行第4列的图片替换成你自己的图片,不要使用setattribute
        function tihuan() {
            var pnode = document.createelement('img');
            pnode.setattribute('src', 'images/2.jpg');
            var oldnode = document.getelementsbytagname('img')[8];
            oldnode.parentnode.replacechild(pnode, oldnode);
            var oldnode = document.createelement('img');
        }
        //    2.删除第3行第2列的图片
        function shanchu() {
            var oldnode = document.getelementsbytagname('img')[11];
            oldnode.parentnode.removechild(oldnode)
        }
点击创建相册所呈现页面
点击替换图片,替换指定位置的图片
点击删除节点,删除指定位置的图片的节点
该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录 Product