jquery循环点击每个按钮上两种文字来回切换

第一种方法:

设为管理员

设为管理员

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

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

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

      $(this).html("取消管理员");

      },function() {

     $(this).html("设为管理员");

 })

});

第二种方法:

设为管理员

设为管理员

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

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

    if(i==0){

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

           $(this).html("");

           $(this).html("取消管理员");

    }else{

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

          $(this).html("");

          $(this).html("设为管理员");

    }

});

你可能感兴趣的:(jquery循环点击每个按钮上两种文字来回切换)