如何显示在一个阵列的图像这就是? JavaScript的 [英] How to display an image thats in an array? JavaScript

查看:162
本文介绍了如何显示在一个阵列的图像这就是? JavaScript的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这code被链接到一个html页面

This code is linked to an html page

images = new Array();
images[0] = new Image();
images[0].src = "images/kate.jpg";
images[1] = new Image();
images[1].src = "images/mila.jpg";

document.write(images[0]);

是正确的设置为数组,如果是我如何真正得到显示我的网页上的图像,因为当我运行此它只返回[对象HTMLImageElement]

is that the proper set up for the array and if it is how do i actually get the image to display on my page because when i run this it only returns "[object HTMLImageElement]"

推荐答案

您可以试试这个:

document.write(images[0].outerHTML);

或者这样:

document.body.appendChild(images[0]);

但是,如果你发现自己做了很多的DOM操作,你应该考虑使用一个工具包,使您的生活更轻松。在 jQuery的,例如,你可以简单地写为:

But if you find yourself doing a lot of DOM manipulation, you should probably consider using a toolkit to make your life easier. In jQuery, for example you could simply write this as:

$("body").append($('<img src="images/kate.jpg" />'));

这篇关于如何显示在一个阵列的图像这就是? JavaScript的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆