经验首页 前端设计 程序设计 Java相关 移动开发 数据库/运维 软件/图像 大数据/云计算 其他经验
当前位置:技术经验 » JS/JS库/框架 » jQuery » 查看文章
jquery点击来回切换
来源:cnblogs  作者:Sea。  时间:2019/9/12 9:10:53  对本文有异议

  做个笔记偶尔用有时记不住

方法一:

  1. <div id="test">
  2. test
  3. </div>

  1. $('#test').mouseover(function () {
  2. $(this).addClass('a')
  3. }).mouseout(function () {
  4. $(this).removeClass('a')
  5. })

方法二:

<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("设为管理员");

 })

});

方法三:

<!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>

 

方法四:

<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("设为管理员");

    }

});

原文链接:http://www.cnblogs.com/zzguan/p/11506490.html

 友情链接:直通硅谷  点职佳  北美留学生论坛

本站QQ群:前端 618073944 | Java 606181507 | Python 626812652 | C/C++ 612253063 | 微信 634508462 | 苹果 692586424 | C#/.net 182808419 | PHP 305140648 | 运维 608723728

W3xue 的所有内容仅供测试,对任何法律问题及风险不承担任何责任。通过使用本站内容随之而来的风险与本站无关。
关于我们  |  意见建议  |  捐助我们  |  报错有奖  |  广告合作、友情链接(目前9元/月)请联系QQ:27243702 沸活量
皖ICP备17017327号-2 皖公网安备34020702000426号