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

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

作者: 闫涵达人 | 来源:发表于2017-03-07 14:55 被阅读0次

第一种方法:

<html>

<div class="people_state">设为管理员</div>

<div class="people_state">设为管理员</div>

<js>

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

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

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

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

      },function() {

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

 })

});

第二种方法:

<html>

<div class="people_state"    res="0">设为管理员</div>

<div class="people_state"    res="0">设为管理员</div>

<js>

$(".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循环点击每个按钮上两种文字来回切换

      本文链接:https://www.haomeiwen.com/subject/sgemgttx.html