我使用這個漂亮的iOS複選框插件Switchery iOS checkbox。默認情況下,該複選框處於禁用狀態。現在,如果用戶單擊具有「btn_modify」類的按鈕,並且在用戶單擊具有「btn_cancel」類的按鈕時將其禁用,則需要啓用切換盒複選框。以下是我的代碼參考。將禁用的屬性設置爲true或false switchery
<input type="checkbox" name="" value="" class="js-switch" checked />
<button class="btn_modify">Modify</button>
<button class="btn_cancel">Cancel</button>
並激活switchery
//switchery
var elems = Array.prototype.slice.call(document.querySelectorAll('.js-switch'));
elems.forEach(function(html) {
var switchery = new Switchery(html, { size: 'small', disabled: true, disabledOpacity: 1.0 });
});
和我嘗試
$(".btn_modify").click(function(){
$(".js-switch").attr("disabled", false);
});
$(".btn_cancel").click(function(){
$(".js-switch").attr("disabled", true);
});
但遺憾的是沒有工作,任何幫助,想法,線索,意見,建議,將不勝感激。謝謝!
您正在使用什麼版本的jQuery?你有沒有包含jQuery庫? – Abhinav
我使用了最新的jquery 2.xx庫,並且我確實包含了它,並且沒有任何問題渲染切換插件 –
文檔就在您鏈接到的頁面上 - 保留對該對象的引用,並調用'.disable() '和'.enable()'。 –