开发者

JS: accessing img attributes that were assigned randomly

I have a page with a block of thumbnails (small images) and I would like a bigger version of the image to appear when a small image is clicked on. Both files have identical names but are in different folders. The problem is, the thumbnails are generated randomly using a for loop. Here is the script I am working on (onclick):

function seeFoto(that){
document.getElementById("photoViewer").style.zIndex="1";
document.getElementById("gallery").style.zIndex="0";
document.getElementById("bigpic").src=.../// <<-- problem: how do I get the source of the thumbnail and then replace "bigpic" with other version of the image??

Here is the script that assigns each cell a random image (it works):

function randomThumbs(){
swapp();
var onecell="1";
for (onecell=1; onecell<33; onecell++){
var duh=Math.ceil(Math.random()*802);
document.getElementById("img" +onecell).setAttribute("src","thumbs/"+duh+".jpg");
}}

swapp() is a function that randomly selects two cells and changes the picture to another random picture. Html code:

<td><a id="link1" href="page.html" <img id="img1" src="thumbs/1.jpg" onclick="seeFoto(this)" /></a></td>
<td><a id="link2" href="page.html" <img id="img2" src="thumbs/2.jpg" onclick="seeFoto(this开发者_Python百科)" /></a></td>

Hope my question is clear enough... Thanks!


document.getElementById("bigpic").src = that.src.replace('thumbs/', 'bigimages/');

I think... :-)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜