我需要有关此toogle功能的帮助。如何更改名称,例如:当"框"显示它只显示SHOW和#34;框"隐藏,它只显示HIDE。
现在显示/隐藏将同时显示在显示和隐藏。
.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>
&#13;
public LignePol(int n) {
Point[] sommets = new Point[n];
}
public LignePol(Point[] sommets) {
this.sommets = sommets;
}
public Point getSommet(int i) {
return sommets[i];
}
public void setSommet(int i, Point p) {
sommets[i] = p;
}
public String toString() {
if (sommets.length == 0)
return "[ ]";
String res = "[ " + sommets[0];
for (int i = 1; i < sommets.length; i++)
res += ", " + sommets[i];
return res + " ]";
}
public Object clone() {
Point[] bis = new Point[sommets.length];
for (int i = 0; i < sommets.length; i++) {
Point p = sommets[i];
bis[i] = new Point(p.x(), p.y());
}
return new LignePol(bis);
}
public void homothetie(double k) {
for (int i = 0; i < sommets.length; i++)
sommets[i].homothetie(k);
}
public void translation(double dx, double dy) {
for (int i = 0; i < sommets.length; i++)
sommets[i].translation(dx, dy);
}
public void rotation(double a) {
for (int i = 0; i < sommets.length; i++)
sommets[i].rotation(a);
}
void tracer() {
for (int i = 1; i < sommets.length; i++)
tracerSegment((int) sommets[i - 1].x(), (int) sommets[i - 1].y(),
(int) sommets[i].x(), (int) sommets[i].y());
}
public static void main(String[] args) {
Point[] t = {
new Point( 1, 3), new Point( 0, 2), new Point( 0, 0),
new Point( 3, 5), new Point( 4, 4), new Point( 0, 4),
new Point( 4, 2), new Point( 4, 0), new Point( 1, 1) };
LignePol lp = new LignePol(t);
double m = Double.parseDouble(args[0]);
double n = Double.parseDouble(args[1]);
double l = Double.parseDouble(args[1]);
lp.homothetie(l / 4.0);
lp.translation(m, n);
lp.tracer();
}
// pour la simulation
static void tracerSegment(int x0, int y0, int x1, int y1) {
System.out.println("(" + x0 + "," + y0 + ") --> (" + x1 + "," + y1 + ")");
}
&#13;
答案 0 :(得分:1)
你可以简单地使用一个计数器..
这是一个小提琴: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();
});
答案 1 :(得分:0)
$(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
时更改基础