gpt4 book ai didi

jQuery:将 Div 内容加载到另一个 div 中?

转载 作者:行者123 更新时间:2023-12-01 02:59:55 25 4
gpt4 key购买 nike

我在页面上有多个隐藏的 div,每个隐藏的 div 包含不同的内容,例如,当我单击页面上的链接时

<a href="#contentone" class="clicky">Load content one</a>
<a href="#contenttwo" class="clicky">Load content two</a>

<div id="contentone">Some content here to be loaded into another div</div>
<div id="contenttwo">Some content here to be loaded into another div</div>

<div id="slider">
This content to be replaced by content from links/hidden divs
</div>

目前我已经有了这个设置,因此它从外部源加载内容,但我更喜欢它用页面上隐藏的内容填充 slider (如上所述)。

我当前的 jquery 如下,希望将其转换为在页面上的隐藏 div 中工作,而不是外部文件。

<script type='text/javascript'>//<![CDATA[ 
$(window).load(function(){
$(function () {
$(".clicky").click(function () {
var url = this.href;
var e = $("#slider");
e.load(url, function() {
e.animate({width: "show"}, 500);
});
return false;
});
});
});//]]>

</script>

最佳答案

您不需要使用.load

$(function () {
$(".clicky").click(function () {
var content_id = $(this).attr('href');
$('#slider').hide().html($(content_id).html()).show(500);
return false;
});
});

THE WORKING DEMO

关于jQuery:将 Div 内容加载到另一个 div 中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12034252/

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