2012-03-04 64 views
0

我有一個jQuery中的圖像數組,我試圖加載到一系列的div當用戶點擊一個特定的框。在我的本地主機上,一切都很好,但是當我上網時。真的很奇怪。使用jquery加載一組圖像

enter image description here

,我嘗試加載URL被分成每個個性和獨立的DIV爲每個字母創建...?

這裏是用於創建div的代碼,併爲所有人簽名背景圖片。

  for (var i = 0, len = images[index].length; i < len; i++){ 
      $('#project_display #slides .slides_container').append($('<div></div>')) 
      $('#project_display #slides .slides_container div').eq(i).css('background','url(' + images[index][i] +') center center no-repeat'); 
     } 

圖像包含其他圖像的數組。 任何幫助將如此偉大!

謝謝!

UPDATE

這裏是圖像和另一個數組創建:

` 變種馬戲團=新的Array(); circus [0] ='images/projects/circus1.jpg'; 馬戲團1 ='images/projects/circus2.jpg'; circus [2] ='images/projects/circus3.jpg'; circus [3] ='images/projects/circus4.jpg'; circus [4] ='images/projects/circus5.jpg';

var images = new Array(); images [0] ='images/projects/radioshack_899.jpg'; 圖片1 = radioImages; images [2] =矮人;
images [3] =矮人;
圖片[4] =馬戲團; `

+0

神聖的廢話,我又把那些眼鏡放在哪裏? – adeneo 2012-03-04 19:56:30

+0

'圖像'的結構是什麼? – 2012-03-04 19:57:34

+0

'圖像'看起來像一串字符串。 'images [index] [i]'然後相當於'images [index] .charAt(i)'。 – 2012-03-04 20:01:16

回答

0

這一點很難說沒有看到更多的,但你要麼做錯事的for循環,或者你正在做的事情錯在url(' + images[index][i] +')

你確定你是images.length is'nt你在找什麼for循環,和東西告訴我,你應該刪除[i]在url(),像這樣:url(' + images[index] +')

也許這應該是像這樣:

for (var i = 0; i < images.length; i++){ 
    $('<div></div>').css('background','url(' + images[i] +') center center no-repeat') 
     .appendTo($('#project_display #slides .slides_container')); 
} 

如果可能,你應該儘量縮短這些選擇器。

+0

以及即時消息幾乎肯定你的權利'url('+ images [index] [i] +')'是問題。事情是圖像[索引]應該返回一個圖像數組,然後我使用'[我]'從中進行選擇。但也許我的語法關閉? – 2012-03-04 20:07:18

+0

@JamesDunay - 如果上面的更新是正確的,那只是一個常規數組,而不是數組中的數組,所以[index]將選擇該數組中的一個字符串值,[i]將選擇一個字符就像Rob W在上面的評論中所說的那樣。 - 您可能需要在for循環中檢查數組'images.length'的長度,然後刪除url()的[index]部分,並讓[i]根據迭代選擇圖像。 – adeneo 2012-03-04 20:14:35

+0

明白了!謝謝 :) – 2012-03-04 20:16:16