将src值从javascript格式化为img标记

时间:2014-03-26 20:36:24

标签: javascript jquery

我需要将我正在完美的图像源放到<img/>位置,但我不知道该怎么做。

JS:

var aa = document.getElementById("TableImage"+getid).src;
alert(aa);

Result of above js:

<code>Result</code>

现在我想在此处添加此链接:

<!-- Upload Part -->
<div class="ImageUpload">
    <label for="FileInput" style="width: 18px; height: 18px; margin-top: -160px; margin-left: 905px;">
        <img class="UplaodPic" src="../../img/Upload_Panel.png"/>
   </label>

    <input name="picture" id="FileInput" type="file" onchange="readURL(this,'Picture2')" style="cursor: pointer; display: none"/>
</div>

我想将Upload_Panel.png图片替换为源aa中的图片。帮助会很好。

2 个答案:

答案 0 :(得分:2)

怎么样:

$("#FileInput").prev("label").find("img").attr("src", aa);

(因为这是唯一带有ID的元素,所以我选择了。不知道你的页面上有多少个类)

答案 1 :(得分:1)

var aa = document.getElementById("TableImage"+getid).src;
$('.uplaodPic').attr('src', aa)