繁体   English   中英

标签-需要内容在页面加载时隐藏并在单击时显示

[英]Tabs - need content to be hidden on page load and revealed when clicked

我已经创建了一个标签系统。 它在JSFiddle上似乎最合适,因为我需要它,但在这里运行错误代码,并且我需要首先隐藏两个选项卡上的选项卡内容,并且仅在单击选项卡(图像)时才显示。 任何人都可以帮助解决这些问题吗?

我是Java的新手。 提前致谢。

我对Java语言只是一个新手,所以需要一些帮助。 提前致谢!

 $('span.a, span.b').click(function() { if (!$(this).hasClass('active')) { $('span.a, span.b').removeClass('active'); $(this).addClass('active'); $('div.a, div.b').toggle(); } }); 
 div { margin-top: 40px; width: 80%; text-align: left; } 
 <center><span class="a active"> <img src="http://cornerstoneparking.portfolio.com.au/wp-content/uploads/2016/10/Customers.jpg" width="200"> </span> <span class="b"> <img src="http://cornerstoneparking.portfolio.com.au/wp-content/uploads/2016/12/Landlords.jpg" width="200"></span> <div class="a">Cornerstone Parking provides value for money parking in Brisbane's CBD and surrounding suburbs. Our turn up and park rates (ie no need to pre-book) are often cheaper than other car park's online discount rates and you can always be sure of getting a bay in a Cornerstone car park. Our convenient and centrally located CBD car parks are run by our friendly staff and are predominantly located in the Adelaide Street, Ann Street and Creek Street areas. Our car parks offer discounted parking in large bays with ample height clearance. We offer hourly (visitor) parking as well as monthly parking, early bird parking and motorbike parking in most of our car parks.</div> <div class="b" style="display:none">Cornerstone Parking provides a high quality, professional and technology driven car park management service. A part of the Cornerstone Group, our property development and management heritage provides us with a true appreciation of landlord issues. Our parent company backing means that Cornerstone Parking has the appetite and ability to participate in larger parking projects, including the development of new car parks. We provide owners, investors and developers with our car park management, advisory and consultation services.</div> </center> 

在body标签的末尾添加jQuery(在代码段中是html代码的末尾)可以解决您的问题。

如果您想知道的话,请告诉我。

由于您的js代码使用jQuery库语法,因此您需要添加jQuery库,如下所示:

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>

对于隐藏部分,您可以通过以下方式使div隐藏:

div.a,
div.b {
  visibility:hidden;
}

然后在js中将可见性编辑为点击可见

$('div.a, div.b').css("visibility","visible")

可见性隐藏了内容,但仍会占用空间。 如果要让不可见内容占据页面中的任何空间,请使用“ display” css属性而不是可见性。

您可以在下面找到完整的代码:

 $('span.a, span.b').click(function() { if (!$(this).hasClass('active')) { $('span.a, span.b').removeClass('active'); $(this).addClass('active'); $('div.a, div.b').toggle(); } $('div.a, div.b').css("visibility","visible") }); 
 div { margin-top: 40px; width: 80%; text-align: left; } div.a, div.b { visibility:hidden; } 
 <center><span class="a active"> <img src="http://cornerstoneparking.portfolio.com.au/wp-content/uploads/2016/10/Customers.jpg" width="200"> </span> <span class="b"> <img src="http://cornerstoneparking.portfolio.com.au/wp-content/uploads/2016/12/Landlords.jpg" width="200"></span> <div class="a">Cornerstone Parking provides value for money parking in Brisbane's CBD and surrounding suburbs. Our turn up and park rates (ie no need to pre-book) are often cheaper than other car park's online discount rates and you can always be sure of getting a bay in a Cornerstone car park. Our convenient and centrally located CBD car parks are run by our friendly staff and are predominantly located in the Adelaide Street, Ann Street and Creek Street areas. Our car parks offer discounted parking in large bays with ample height clearance. We offer hourly (visitor) parking as well as monthly parking, early bird parking and motorbike parking in most of our car parks.</div> <div class="b" style="display:none">Cornerstone Parking provides a high quality, professional and technology driven car park management service. A part of the Cornerstone Group, our property development and management heritage provides us with a true appreciation of landlord issues. Our parent company backing means that Cornerstone Parking has the appetite and ability to participate in larger parking projects, including the development of new car parks. We provide owners, investors and developers with our car park management, advisory and consultation services.</div> </center> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script> 

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM