这是我的HTML:

<div class="large">
    <img src="/images/photos/Interior.jpg" alt="The interior" style="[...]" />
    <div class="caption">The interior</div>
</div>
<div class="small">
    <img src="/images/photos/Bedroom.jpg" alt="Bedroom" style="[A different ...]" />
    <div class="caption">A bedroom</div>
</div>

单击div.small时,我希望图像和标题都可以交换容器div。要注意的是,我不能只交换src,因为有一堆需要保留的内联样式集。最后,一旦交换了图像,我想将自定义函数.fitToParent()应用于这两个图像。

我将如何去做呢?

最佳答案

$(document).ready(function() {
    $('div.small').click(function() {
        var bigHtml = $('div.large').html();
        var smallHtml = $(this).html();

        $('div.large').html(smallHtml);
        $('div.small').html(bigHtml);

        //custom functions?
    });
});

10-05 20:52
查看更多