取消选中或关闭所有基于复选框的拨动开关,当新开关打开时? [英] Uncheck or turn off all checkbox based toggle switches when a new one is turned on?

查看:103
本文介绍了取消选中或关闭所有基于复选框的拨动开关,当新开关打开时?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的一个项目中使用了一些CSS3拨动开关,它们目前正好进行拨动,但是我希望发生的事情是在激活一个新开关时将所有其他拨动开关关闭.谁能帮助我开始做这件事.我什至不知道从哪里开始.这些是我正在使用的切换:

I am using some CSS3 toggle switches in a project of mine and they are currently toggling just fine, but what i would like to have happen is for all other toggles to turn off when a new one is activated. Can anyone help get me started on this. I am not even sure where to start. These are the toggles I am using:

http://wsnippets.com/styling-checkbox-toggle-switches-css3/

有没有一种方法可以使Javascript做到这一点?任何指导都会有所帮助.

is there a way for Javascript to be able to do this? Any guidance would be helpful.

推荐答案

如果您使用的是jQuery,这将达到目的:

If you're using jQuery, this will do the trick:

$(function() {
  $('.checkbox-switch input').change(function() {
    if($(this).prop('checked')) {
      $(".checkbox-switch input").prop('checked', false);
      $(this).prop('checked', true);
    }
  });
});

在此处的链接中使用示例html/css查看演示: http://codepen.io/anon/pen/MymGqP .

See the demo using the example html/css in your link here: http://codepen.io/anon/pen/MymGqP.

这篇关于取消选中或关闭所有基于复选框的拨动开关,当新开关打开时?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆