Getting an image url from Jquery using javascript - Stack Overflow

I have a Jquery function that have many url for image ojbect.How can i get the url of the image using

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.

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.

Share Improve this question edited Oct 14, 2013 at 8:02 nietonfir 4,8816 gold badges33 silver badges44 bronze badges asked Oct 14, 2013 at 7:57 user2878048user2878048 451 silver badge5 bronze badges 2
  • 1 what exactly do you need here? – geevee Commented Oct 14, 2013 at 7:59
  • I want to extract the url of the current image using javascript. – user2878048 Commented Oct 14, 2013 at 8:06
Add a ment  | 

2 Answers 2

Reset to default 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.

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

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1742415098a4439588.html

相关推荐

  • Getting an image url from Jquery using javascript - Stack Overflow

    I have a Jquery function that have many url for image ojbect.How can i get the url of the image using

    3小时前
    30

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信