我需要在按钮的单击事件上使用jquery禁用switchery复选框。我知道有一个disable()方法,但我不知道如何在函数中使用它,因为问题是我必须首先检索所有初始化了switchery的复选框,但我不知道如何使用。
我的jsfiddle示例:https://jsfiddle.net/g94gkaL7/38/
发布于 2018-02-13 19:30:08
保持对创建的switchery项的引用,然后遍历它们并调用disable。
var elems = Array.prototype.slice.call(document.querySelectorAll('.js-switch'));
var switcheries= [];
elems.forEach(function(html, index) {
var switchery = new Switchery(html,{size: 'small',});
switcheries[index] = switchery;
});
$("#dis").on("click", function(){
$("input[type='checkbox']").attr("disabled", true); // works for standard input checkbox only
// now i want to retrieve all existing swithcery to disable them
//switchery.disable();
switcheries.forEach(item => item.disable());
});
});发布于 2018-02-13 19:32:11
var switcherylist = [];
$(document).ready(function() {
//switchery
//var checkbox = document.querySelector('.js-switch');
var elems = Array.prototype.slice.call(document.querySelectorAll('.js-switch'));
elems.forEach(function(html) {
var switchery = new Switchery(html,{size: 'small',});
switcherylist.push(switchery);
});
$("#dis").on("click", function(){
$("input[type='checkbox']").attr("disabled", true); // works for standard input checkbox only
switcherylist.forEach(function(switchery) {
switchery.disable();
});
// now i want to retrieve all existing swithcery to disable them
//switchery.disable();
});
});https://stackoverflow.com/questions/48765631
复制相似问题