我有一系列图像填充页面,我遇到的问题是想出一种从缩略图创建一个ONCLICK弹出图像窗口的方法(但弹出窗口需要是一个更大尺寸的图像):
这是js代码:
var str = "<table>";
var imgFolder = "images/";
var cover = new Array();
cover[0] = "kitchenHouseSale.jpg";
cover[1] = "eatLive.jpg";
cover[2] = "loveAnthonySale.jpg";
var coverone = new Array();
coverone[0] = "casualVacancy.jpg";
coverone[1] = "quiet.jpg";
coverone[2] = "whirlAway.jpg";
var covertwo = new Array();
covertwo[0] = "everyLastSale.jpg";
covertwo[1] = "neilYoung.jpg";
covertwo[2] = "soupSisters.jpg";
var title = new Array();
title[0] = "The Kitchen House";
title[1] = "Eat to Live";
title[2] = "Love Anthony";
for (var i = 0; i < cover.length; i++)
{
str += "<tr><td colspan='2'><h2>" + category[i] + "</h2></td></tr>";
str += "<tr><td class='basket'><img src='" + imgFolder + cover[i] + "' width='108' height='159'>
}
str += "</table>";
var elem = document.getElementById("table");
elem.innerHTML = str;
感谢任何帮助。谢谢!
答案 0 :(得分:0)
我能帮到你吗?您希望用户单击图像,同一图像的更大版本应该出现在弹出窗口中吗?
看看window.open()然后:http://w3schools.com/jsref/met_win_open.asp 您必须指定图像的绝对路径 - 文件作为弹出窗口的URL,如http://your.domain.com/images/kitchenHouseSale.jpg。
然后你可以在img-tag中添加一个onclick-handler,如下所示:
<img src='" + imgFolder + cover[i] + "' width='108' height='159' onclick="window.open('http://your.domain.com + this.src)" />