2

I have a Jquery function that have many url for image ojbect. How can i get the url of the image using javascript. I want to make a test on the url

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

You can find below example of the code.

$(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...

The ID of the DIV is show_banners.

4

2 回答 2

5

in order to extract a src from an image in JavaScript:

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

in jQuery:

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

hope that helps.

于 2013-10-14T08:08:45.600 回答
0

Like so:

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: ""
  })

}

Change i<=5 to the amount of rows you have. Then in the code you posted above put:

images: image_array

于 2013-10-14T08:06:35.480 回答