gpt4 book ai didi

javascript - 使用 jQuery 交换 div 内容

转载 作者:太空狗 更新时间:2023-10-29 13:39:20 24 4
gpt4 key购买 nike

这是我的 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?
});
});

关于javascript - 使用 jQuery 交换 div 内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1380810/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com