首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何使用jquery动态更改以禁用切换

如何使用jquery动态更改以禁用切换
EN

Stack Overflow用户
提问于 2019-10-28 17:52:01
回答 1查看 151关注 0票数 1

我能问一下谁知道怎么换开关吗?例如,我有一个父交换机,如果父交换机关闭,它将禁用它的子交换机

页面工作得很好,但是如果父开关关闭,我找不到jquery来对开关进行动态更改。提前感谢您的回答

代码语言:javascript
复制
if ($(".js-switch")[0]) {
    var elems = Array.prototype.slice.call(document.querySelectorAll('.js-switch'));
    elems.forEach(function (html) {
        var switchery = new Switchery(html, {
            color: '#26B99A'
        });
    });
}
代码语言:javascript
复制
<link href="https://cdnjs.cloudflare.com/ajax/libs/switchery/0.8.2/switchery.css" rel="stylesheet" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/switchery/0.8.2/switchery.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>

<input type="checkbox" class="js-switch" name="write[33]" id="write[33]"  />
  <label class="onoffswitch-label" for="write[33]">
  <span class="onoffswitch-inner"></span>
  <span class="onoffswitch-switch"></span>
</label>
<input type="checkbox" class="js-switch" name="write[34]" id="write[34]"  />
  <label class="onoffswitch-label" for="write[34]">
  <span class="onoffswitch-inner"></span>
  <span class="onoffswitch-switch"></span>
</label>
<input type="checkbox" class="js-switch" name="write[35]" id="write[35]"  />
  <label class="onoffswitch-label" for="write[35]">
  <span class="onoffswitch-inner"></span>
  <span class="onoffswitch-switch"></span>
</label>

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2019-10-29 10:38:22

尝尝这个

代码语言:javascript
复制
$('.js-switch').each(function(idx, elm) {
  new Switchery(elm, {
    color: '#26B99A'
  });
});
$('.js-parent').on('change', function() {
  $('.js-child').each(function() {
    this.click();
  });
});
代码语言:javascript
复制
<link href="https://cdnjs.cloudflare.com/ajax/libs/switchery/0.8.2/switchery.css" rel="stylesheet" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/switchery/0.8.2/switchery.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<input type="checkbox" class="js-switch js-parent" /> Parent
<br><br>
<input type="checkbox" class="js-switch js-child" /> Child 1
<input type="checkbox" class="js-switch js-child" /> Child 2

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/58588759

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档