【问题标题】:Bootstrap switch Toggle - One is on, the other is off using checkbox and jQuery [closed]引导开关切换 - 一个打开,另一个关闭使用复选框和 jQuery [关闭]
【发布时间】:2017-12-07 09:36:06
【问题描述】:

使用复选框和 jQuery 帮助我进行 Bootstrap 开关切换 - 一个打开,另一个关闭。

<input type="checkbox" data-toggle="toggle" data-style="ios" data-size="normal" data-on="&#8203;" data-off="&#8203;" onclick="change_ins(1)" class="switch switch-on toggle" checked value="true" id="toggle1">
<input type="checkbox" data-toggle="toggle" data-style="ios" data-size="normal" data-on="&#8203;" data-off="&#8203;" onclick="change_ins(2)" class="switch switch-off toggle" id="toggle2">
<input type="checkbox" data-toggle="toggle" data-style="ios" data-size="normal" data-on="&#8203;" data-off="&#8203;" onclick="change_ins(3)" class="switch switch-off toggle" id="toggle3">
<input type="checkbox" data-toggle="toggle" data-style="ios" data-size="normal" data-on="&#8203;" data-off="&#8203;" onclick="change_ins(4)" class="switch switch-off toggle" id="toggle4">
<input type="checkbox" data-toggle="toggle" data-style="ios" data-size="normal" data-on="&#8203;" data-off="&#8203;" onclick="change_ins(5)" class="switch switch-off toggle" id="toggle5">

【问题讨论】:

  • 看起来你没有太多时间写代码,非常准确,让我们看看你什么时候开始被否决
  • 请准确回答您的问题

标签: javascript php jquery twitter-bootstrap


【解决方案1】:

$(".toggle123").change(function() { 
		var tid= this.id;
		
   if ($(this).is(":checked")) {
	    $('.toggle123').each(function() {
    if(this.id != tid){ $("#"+this.id).bootstrapToggle('off'); }
});
      /* $(".toggle").bootstrapToggle('off');
	  */
	  
  } 
});
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css" rel="stylesheet"/>
<link href="https://gitcdn.github.io/bootstrap-toggle/2.2.2/css/bootstrap-toggle.min.css" rel="stylesheet"/>

<input type="checkbox" data-toggle="toggle" data-style="ios" data-size="normal" data-on="&#8203;" data-off="&#8203;" class="switch switch-on toggle toggle123"  id="toggle1">
<input type="checkbox" data-toggle="toggle" data-style="ios" data-size="normal" data-on="&#8203;" data-off="&#8203;" class="switch switch-off toggle toggle123" id="toggle2">

<input type="checkbox" data-toggle="toggle" data-style="ios" data-size="normal" data-on="&#8203;" data-off="&#8203;" class="switch switch-off toggle toggle123" id="toggle3">

<input type="checkbox" data-toggle="toggle" data-style="ios" data-size="normal" data-on="&#8203;" data-off="&#8203;" class="switch switch-off toggle toggle123" id="toggle4">

<input type="checkbox" data-toggle="toggle" data-style="ios" data-size="normal" data-on="&#8203;" data-off="&#8203;" class="switch switch-off toggle toggle123" id="toggle5">

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://gitcdn.github.io/bootstrap-toggle/2.2.2/js/bootstrap-toggle.min.js"></script>

【讨论】:

  • 即使答案被接受了,它对未来的用户还是有用的,如果你包含一些文字来解释为什么这个答案是 Q
猜你喜欢
  • 2023-01-31
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-10-01
  • 2021-04-18
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多