Jquery 通过切换按钮中图标的类来控制出现不同的按钮图标

<!DOCTYPE html>
<html>
<head>
<title>通过切换按钮中图标的类来控制出现不同的按钮图标</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<pre name="code" class="html"><link href="http://libs.baidu.com/bootstrap/3.0.3/css/bootstrap.min.css" rel="stylesheet">
   <script src="http://libs.baidu.com/jquery/2.0.0/jquery.min.js"></script>
   <script src="http://libs.baidu.com/bootstrap/3.0.3/js/bootstrap.min.js"></script>
<style tyle="text/css">.class1{font-size:120%;color:green;}.class2{font-size:120%;color:red;}</style><script type="text/javascript">$(document).ready(function(){ $('#togglebutton').click(function(){ //alert("test"); var $btn = $(this), on = 'glyphicon-volume-up', off = 'glyphicon-volume-off', $icon = $btn.find('span'), //$p = $('#p1'), btnon = 'btn btn-success', btnoff = 'btn btn-warning'; //这里通过切换按钮中图标的类来控制出现不同的按钮图标,每次点击来回切换声音开关图标 $icon.toggleClass(on).toggleClass(off); $('#p1').toggleClass("class1").toggleClass("class2"); $("#btn1").toggleClass(btnon).toggleClass(btnoff); //$btn.button('toggle'); 如果不想使用html中的data-toggle定义,可以使用这样js实现按钮切换状态效果 });});</script></head><body><div><!-- 添加一个切换效果,使用data-toggle属性 --><button id="togglebutton" class="btn btn-lg btn-default" data-toggle="button"> <span class="glyphicon glyphicon-volume-up"></span></button><p id='p1'>This is a paragraph.</p><button id="btn1" class="btn">Button</button></div><hr/><form> <div class="form-group"><label for="exampleInputEmail1">Email address</label><input type="email" class="form-control" id="exampleInputEmail1" placeholder="Email"> </div> <div class="form-group"><label for="exampleInputPassword1">Password</label><input type="password" class="form-control" id="exampleInputPassword1" placeholder="Password"> </div> <div class="form-group"><label for="exampleInputFile">File input</label><input type="file" id="exampleInputFile"><p class="help-block">Example block-level help text here.</p> </div> <div class="checkbox"><label> <input type="checkbox"> Check me out</label> </div> <button type="submit" class="btn btn-default">Submit</button></form><hr/><div class="dropdown"> <!-- Link or button to toggle dropdown --> <ul class="dropdown-menu" role="menu" aria-labelledby="dLabel"> <li><a tabindex="-1" href="#">行为</a></li> <li><a tabindex="-1" href="#">其它行为</a></li> <li><a tabindex="-1" href="#">特别行为</a></li> <li class="divider"></li> <li><a tabindex="-1" href="#">分割链接</a></li> </ul> </div><hr/></body></html>
 


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值