显示/隐藏内容
Show / Hidden Content
我需要有关此 toogle 功能的帮助。如何改名,例如:"box"显示时只显示SHOW,"box"隐藏时只显示HIDE。
现在显示/隐藏将显示在显示和隐藏上。
$(document).ready(function(){
$(".show").click(function(){
$(".apaansi").toggle();
});
});
.box {
border:1px solid #dedede;
padding:1%;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="uniquename">
<div class="apaansi">
<div class="box col-lg-12 col-md-12 col-sm-12 col-xs-12"> Search </div>
</div>
<div class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
<a href="#" class="show show-car"> Show / Hide <i class="fa fa-chevron-down"></i> </a>
</div>
</div>
你可以简单地使用一个计数器..
这里是 fiddle:https://jsfiddle.net/LL5xhapL/
$counter = 0;
$(".show").click(function(){
if($counter % 2)
{
$(this).html('Hide <i class="fa fa-chevron-down"></i>');
}else{
$(this).html('Show <i class="fa fa-chevron-right"></i>');
$counter = 0;
}
$counter++;
$(".apaansi").toggle();
});
$(document).ready(function() {
$(".show").click(function() {
$(".apaansi").toggle();
$('.apaansi').css('display') == 'none' ? $(this).text('Show') : $(this).text('Hide'); //show hide base on css
});
});
.box {
border: 1px solid #dedede;
padding: 1%;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="uniquename">
<div class="apaansi">
<div class="box col-lg-12 col-md-12 col-sm-12 col-xs-12">Search</div>
</div>
<div class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
<a href="#" class="show show-car"> Hide <i class="fa fa-chevron-down"></i> </a>
</div>
</div>
将显示的默认文本设置为隐藏,然后根据 div
的显示进行更改
我需要有关此 toogle 功能的帮助。如何改名,例如:"box"显示时只显示SHOW,"box"隐藏时只显示HIDE。
现在显示/隐藏将显示在显示和隐藏上。
$(document).ready(function(){
$(".show").click(function(){
$(".apaansi").toggle();
});
});
.box {
border:1px solid #dedede;
padding:1%;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="uniquename">
<div class="apaansi">
<div class="box col-lg-12 col-md-12 col-sm-12 col-xs-12"> Search </div>
</div>
<div class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
<a href="#" class="show show-car"> Show / Hide <i class="fa fa-chevron-down"></i> </a>
</div>
</div>
你可以简单地使用一个计数器..
这里是 fiddle:https://jsfiddle.net/LL5xhapL/
$counter = 0;
$(".show").click(function(){
if($counter % 2)
{
$(this).html('Hide <i class="fa fa-chevron-down"></i>');
}else{
$(this).html('Show <i class="fa fa-chevron-right"></i>');
$counter = 0;
}
$counter++;
$(".apaansi").toggle();
});
$(document).ready(function() {
$(".show").click(function() {
$(".apaansi").toggle();
$('.apaansi').css('display') == 'none' ? $(this).text('Show') : $(this).text('Hide'); //show hide base on css
});
});
.box {
border: 1px solid #dedede;
padding: 1%;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="uniquename">
<div class="apaansi">
<div class="box col-lg-12 col-md-12 col-sm-12 col-xs-12">Search</div>
</div>
<div class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
<a href="#" class="show show-car"> Hide <i class="fa fa-chevron-down"></i> </a>
</div>
</div>
将显示的默认文本设置为隐藏,然后根据 div
的显示进行更改