Click jquery toggle

  Make a note occasionally sometimes can not remember

method one:

<div id="test">
    test
</div>

 $('#test').mouseover(function () {
        $(this).addClass('a')
  }).mouseout(function () {
       $(this).removeClass('a')
  })

Method Two:

<Div class = "people_state"> Set Administrator </ div>

<Div class = "people_state"> Set Administrator </ div>

<js>

$(".people_state").each(function() {

      $(".people_state").bind("click");

      $(".people_state").toggle(function() {

      $ (This) .html ( "Cancel Administrator");

      },function() {

     $ (This) .html ( "Set Administrator");

 })

});

Method three:

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<style>
div{
height: 600px;
width: 300px;
background-color: orange;
}
.a{
background-color: blue;
}
</style>
<title>Title</title>
<script src="jquery-3.1.1.min.js"></script>
</head>
<body>
<div id="d">
sakdas
</div>
</body>
<script>
$('#d').mouseover(function () {
// 俩个状态来回切换
$(this).toggleClass('a')
}).mouseout(function () {
$(this).toggleClass('a')
})
</script>
</html>

 

Method four:

<html>

<Div class = "people_state" res = "0"> Set Administrator </ div>

 

 

<Div class = "people_state" res = "0"> Set Administrator </ div>

 

<js>

$(".people_state").click(function() {

    var  i=$(this).attr("res");

    if(i==0){

           $(this).attr("res","1");

           $(this).html("");

           $ (This) .html ( "Cancel Administrator");

    }else{

          $(this).attr("res","0");

          $(this).html("");

          $ (This) .html ( "Set Administrator");

    }

});

Guess you like

Origin www.cnblogs.com/zzguan/p/11506490.html