2012-02-23 64 views
0

嗨,這是我的代碼的一部分。 我需要將數組中的每個圖像鏈接到不同的URL。 這是甚至有可能從內部做到這一點,如 dataArrClothes.push(["imagename.jpg","<a href="someurl"></a> "Description"]); 任何幫助,非常感謝。Javascript,如何將數組元素鏈接到不同的URL

var dataArrClothes = new Array(); 
dataArrClothes.push(["imagename.jpg", "Description"]); 
dataArrClothes.push(["imagename.jpg", "Description"]); 
+0

對不起,我不明白你想要什麼。你能更清楚嗎? – 2012-02-23 21:00:09

+0

可以更詳細地解釋「將圖像鏈接到不同的URL」是什麼意思? – 2012-02-23 21:01:10

回答

2

你可能想使用對象而不是數組的數組的數組..

var dataArrClothes = []; 

dataArrClothes.push({ img_src: "imagename.jpg", description: "Description"}); 

dataArrClothes.push({ img_src: "imagename.jpg", description: "Description"}); 

這會爲您提供以下...

dataArrClothes[0].img_src; // "imagename.jpg" 

dataArrClothes[0].description: // "Description" 

然後你有具有img_srcdescription屬性的對象數組。

0

您可以使用對象文本,如:

dataArrClothes.push(
    {ImageUrl: 'imagename.jpg', 
    Description: 'Your description here' 
    }); 
相關問題