在页面加载克隆第一张图片集合的照片

时间:2012-03-21 11:18:04

标签: jquery

在我的页面上,我正在收集照片,并将它们存储为showImage div下方的拇指,需要使用克隆的图像进行刷新。 基本上一切正常,除非我需要用第一张图片填充这个showImage div onpage加载,然后使用这个已经有效的onclick克隆。

<a href="/Property/GetImage/someIntId">
  <img id="someIntId" class="details" width="100" height="100" src="/Property/GetImage/7" alt="">
</a>

function onPopUp() {
        $(".details").click(function (event) {
            //clone the clicked image
            var clone = $(this).clone();
            clone.height("250px").width("280px");
            //place it in the placeholder
            $('div#showImage').html(clone);
        });
    }

1 个答案:

答案 0 :(得分:1)

也许这就是你要找的东西?

http://www.w3schools.com/jsref/event_body_onload.asp

<html>
<head>
<script type="text/javascript">
function onPopUp() {
    $(".details").click(function (event) {
        //clone the clicked image
        var clone = $(this).clone();
        clone.height("250px").width("280px");
        //place it in the placeholder
        $('div#showImage').html(clone);
    });
}
</script>
</head>

<body onload="onPopUp()">
<a href="/Property/GetImage/someIntId">
   <img id="someIntId" class="details" width="100" height="100" src="/Property/GetImage/7" alt="">
</a>
</body>
</html> 

或者,你使用jQuery吗?

$(document).ready(function(){
   function onPopUp() {
    $(".details").click(function (event) {
        //clone the clicked image
        var clone = $(this).clone();
        clone.height("250px").width("280px");
        //place it in the placeholder
        $('div#showImage').html(clone);
    });
}
});