How do I get URL of upload file into script

风格不统一 提交于 2019-12-11 02:44:23

问题


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


回答1:


Something like:

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



回答2:


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...)



来源:https://stackoverflow.com/questions/8488224/how-do-i-get-url-of-upload-file-into-script

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!