gpt4 book ai didi

javascript - 使用 jquery 加载隐藏的 div - 检测哪个 div

转载 作者:行者123 更新时间:2023-12-03 02:55:04 24 4
gpt4 key购买 nike

我有一个包含一些隐藏 div 的页面,它们仅在单击链接时才会显示。

将从这个空白的摘要页面开始

enter image description here

当单击“关于”时,它将加载有关内容

enter image description here

等等......但是,我的脚本现在并不像我希望的那样动态。如何隐藏当前显示的 div 并加载用户单击的 div?就目前而言,脚本就好像在页面加载时用户将首先单击每个链接...

$(function() {
$.ajaxSetup({
cache: false
});

var ajax_load = "<img id='loader' class='loader' src='http://gifimage.net/wp-content/uploads/2017/08/loading-gif-transparent-4.gif' />";

$("#abt-ctrl").click(function() {
$('#content-services a').removeClass('active');
$(this).addClass('active');

$("#service-content").fadeOut('fast', function() {
$("#service-content").html(ajax_load);
$("#service-content").fadeIn('slow', function() {
$("#loader").hide();
$('#about-content').fadeIn();
});
});
});

$("#more").click(function() {
$('#content-services a').removeClass('active');
$(this).addClass('active');
$("#service-content").fadeOut('fast', function() {
$("#service-content").html(ajax_load);
$("#service-content").fadeIn('slow', function() {
$("#loader").hide();
$('#more-content').fadeIn();
});
});
});
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="wrapper wrapper-content content-bg content-left-padding">
<div id="service-content" class="row">
<h2 style="margin-top: 22px; margin-left: 40px;max-width: 700px;margin-right: 50px;">Summary</h2>
<p style="margin-left: 40px;max-width: 700px;margin-right: 50px;"></p>

</div>
<div id="about-content" class="hideme row">
<div class="col-lg-12">
<h2 style="margin-top: 22px; margin-left: 40px;max-width: 700px;margin-right: 50px;">About </h2>
<p style="margin-top: 41px; margin-left: 40px;max-width: 700px;margin-right: 50px;">
Gummi bears chocolate caramels biscuit bonbon. Candy donut apple pie. Bear claw apple pie sugar plum tiramisu jelly donut. Liquorice marzipan biscuit gummi bears dragée marshmallow. Jelly-o marshmallow candy pie gummi bears jujubes candy canes pie. Pastry
gummi bears gummies cheesecake biscuit fruitcake candy canes soufflé soufflé. Chocolate bar apple pie jelly. Jelly croissant chocolate bar icing tart apple pie candy bonbon jelly beans. Chocolate lollipop soufflé tiramisu carrot cake danish sesame
snaps soufflé.

</p>
</div>
</div>
<div id="more-content" class="hideme row">
<div class="col-lg-12">
<h2 style="margin-top: 22px; margin-left: 40px;max-width: 700px;margin-right: 50px;">More</h2>
<p style="margin-top: 41px; margin-left: 40px;max-width: 700px;margin-right: 50px;">
Croissant tart donut bear claw soufflé halvah. Brownie croissant chocolate. Pudding fruitcake gingerbread biscuit chocolate croissant gummi bears. Jujubes powder sugar plum tootsie roll caramels carrot cake tart icing. Cake oat cake chocolate cake gummies
carrot cake jujubes carrot cake. Sweet cake chocolate cake fruitcake cookie pie gingerbread cupcake cookie. Marshmallow tiramisu wafer croissant tootsie roll. Wafer sweet roll cupcake chocolate cake apple pie croissant marshmallow muffin.
</p>
</div>
</div>
</div>

最佳答案

做这样的事情

$(".wrapper a").on("click",function(){
// without using any unique/id. We detect based on their index position. link index = hideme index
var ind = $(this).index('a');
$(".wrapper a").removeClass("active");
$(this).addClass("active");

$(".wrapper-content .hideme").hide();
$(".wrapper-content .hideme").eq(ind).show();
});

还有jsfiddle:https://jsfiddle.net/synz/fdq6f35z/

关于javascript - 使用 jquery 加载隐藏的 div - 检测哪个 div,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47669972/

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