2013-10-14 133 views
2

我有一個jquery函數,它有許多圖像ojbect的url。 我怎樣才能得到使用JavaScript的圖像的網址。 我希望做一個測試的網址使用javascript從jquery獲取圖像url

if url=condition {//do something... 

你可以找到例子代碼的下方。

$(document).ready(function() { 
    $(function() { 
     $("#show_banners").showcase({ 
      css: { 
       "margin-left": "auto", 
       "margin-right": "auto" 
      }, 
      animation: { 
       type: "fade", 
       interval: 4500, 
       speed: 1800 
      }, 
      images: [{ 
       url: "../images/content/example1.jpg", 
       description: "example1", 
       target: "_self", 
       link: "" 
      }, { 
       url: "../images/content/example2.jpg", 
       description: "example2", 
       target: "_self", 
       link: "" 
      }, { 
       url: "../images/content/example3.jpg... 

DIV的ID是show_banners

+1

你究竟需要什麼? – geevee

+0

我想使用javascript提取當前圖像的網址。 – user2878048

回答

5

爲了提取圖像中的JavaScript一個src:

var img_src = document.getElementById('elementId').src; 
jQuery中

var img_src = $('#elementId').attr('src'); 

希望幫助。

+0

當我這樣做時返回的消息是「未定義」。 – user2878048

+0

我需要獲取show_banner的元素ID, ,然後獲取圖片url – user2878048

+0

嘗試使用jQuery:$('#elementId img')。attr('src') – geevee

0

像這樣:

var image_array = [] 

for(var i=1; i<=5; i++) { 

    image_array.push({ 
    url: "../images/content/example"+i+".jpg", 
    description: "example"+i, 
    target: "_self", 
    link: "" 
    }) 

} 

更改i<=5給你行的數量。然後,在你的代碼貼上面放:

images: image_array

+0

但我需要第一個獲取div的元素show_banner – user2878048