How do I get URL of upload file into script

2019-07-12 20:04发布

Upon upload completion, my newly uploaded file has the URL of

    <div id="uploaded-file">

    <img src="http://path-to-my-file.jpg" />

    </div>

How do I get the URL of that uploaded file into my script?

    <script>
    script stuff.use this.etc
    ('http://path-to-my-file.jpg')
    });
    </script>

Thanks in advance for any assistance!

EDIT:

I used:

    <script>
    var myurl = document.getElementById("uploaded-file").getElementsByTagName("img")[0].src;   

    </script>

then replace the hardcoded url:

    Layer_3.mousedown(function() { this.animate({ fill:
    'url("http://farm5.staticflickr.com/4067/4584507098_b887327eae.jpg")' }, 600); });

with

    Layer_3.mousedown(function() { this.animate({ fill: 'url(' + myurl + ')' }, 600); });

Here is JSFiddle

2条回答
Summer. ? 凉城
2楼-- · 2019-07-12 20:36

Something like:

<script>
    var myurl = document.getElementById("uploaded-file").getElementsByTagName("img")[0].src;   
    alert(myurl);
</script>
查看更多
ゆ 、 Hurt°
3楼-- · 2019-07-12 20:51

Using jQuery (though you could use vanilla JS instead)...

uploadedImg = $('#uploaded-file').find('img');
imgSrc = uploadedImg.attr('src');

You then have the src as a variable...

(That's all I can give you without more information. There are probably better ways of doing this, but your initial problem isn't really clear...)

查看更多
登录 后发表回答