如何在一个div中获取图像的来源?

时间:2013-07-11 05:21:10

标签: jquery html css

我正在进行UI设计,如果我点击它,我怎样才能将图像的来源在一个div到另一个div中。 就像在FB中一样,我怎样才能将全屏图像的来源放到右侧按钮上。  我正在使用jQuery,html,css。

全屏:

$('.fullscreen').bind('click', function(event) {
    var sectionId = $(this).parents('ul').attr('id');
    var outputId  sectionId.replace('ul','img');
    var fullObj = $('#singleTemp').clone();
    var imgTarget = $('#' + outputId).attr('src');

    fullObj.find('#full').attr('src', imgTarget);

    $('#fullscreenTemp').html(fullObj.html());

    var target = document.getElementById('fullscreenTemp');
    $('#fullscreenTemp').show();

    screenfull.request(target);
});

screenfull.js是我的全屏插件

html到箭头:

<div id="singleTemp" style="display:none">
    <div id="fullDiv" style="text-align: center">
        <div class="fs-main"> 
            <div class="fs-pic">
                <img id="full" style="max-height:100%; max-width:100%;" alt="imagecontainer image" src=""/>
            </div>
            <div class="fs-leftarrow">
                <img  id="1" src="jqe13/image/leftarrow.PNG"/>
            </div>
            <div class="fs-rightarrow">
                <img src="jqe13/image/rightarrow.PNG"/>
            </div>
            <div class="fs-remove">
                <img src="jqe13/image/removee.png" height="20"onclick=""/>
            </div>
            <div class="fs-like">
                <img src="jqe13/image/like.PNG" height="45"/>
            </div>
            <div class="fs-unlike">
                <img src="jqe13/image/unlike.PNG" height="45"/>
            </div>
        </div>
    </div>
</div>

html到图片:

<div id="outputTemp" style="display:none">
<div id="rightoutputimgae">
<div id="rightimgId" class="rightimg"  rel="tooltip" content="
     <img src='jqe13/image/1.jpg' class='tooltip-image'/> ">
<div id="outputimageId" class="outputimage">
  <img src="jqe13/image/1.jpg" alt="Right Bottom Image"></div>
</div>
<ul>
  <li id="outfullscreen"><a href="#">
    <img src="jqe13/image/fullscreen_c.PNG" alt="Full Screen" class="fullscreen" 
     title="Full Screen"></a></li>
    </ul>
 </div>

我在outputimageId中有图像。

4 个答案:

答案 0 :(得分:1)

var src = $("#someImg").attr("src");

var src = $("#otherImg").attr("src",src);

只需设置src

即可

答案 1 :(得分:0)

我认为你正在寻找滑块效果。有很多jquery滑块插件可以免费使用。

例如:http://www.hongkiat.com/blog/jquery-image-galleries-sliders-best-of/

Demo

答案 2 :(得分:0)

您可以使用以下代码:

/// First div
<div id="first">
    <img alt="example" src="\images\test.jpg" />
 </div>

// second div 
<div id="first">
    <img alt="example2" src="\images\blank.jpg" />
 </div>



var divsrc1 = $('img[alt="example"]').attr('src');

var divsrc2 = $('img[alt="example2"]').attr('src');
divsrc2 = divsrc1;
alert("source of image with alternate text = example - " + divsrc2);

以下是Demo

使用以下代码:

var divsrc1 = $('#first img').attr('src');
//alert("source of image with alternate text = example - " + divsrc1);
var divsrc2 = $('#sec img').attr('src');
//alert("source of image with alternate text = example - " + divsrc2);
divsrc2 = divsrc1;
alert("source of image with alternate text = example - " + divsrc2);

答案 3 :(得分:0)

var input = $("#rightoutputimgae").prop("src");
$("#otherImg").prop("src",input );