0

我有一组填充页面的图像,我遇到的问题是想出一种从缩略图创建 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;

任何帮助表示赞赏。谢谢!

4

1 回答 1

0

我说得对吗?您希望用户单击图像,并且应该在弹出窗口中显示同一图像的更大版本?

看看 window.open() 然后:http://w3schools.com/jsref/met_win_open.asp 您必须指定图像的绝对路径 - 文件作为弹出窗口的 url,例如http://your.domain .com/images/kitchenHouseSale.jpg

然后,您可以将 onclick-handler 添加到 img-tag,如下所示:

<img src='" + imgFolder + cover[i] + "' width='108'    height='159' onclick="window.open('http://your.domain.com + this.src)" />
于 2012-11-05T19:39:56.387 回答