2013-10-14 135 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