如何禁用我的切换按钮?这是我的代码

时间:2016-05-08 09:00:36

标签: javascript jquery

<label class="switch switch-yes-no" id="check_'+id+'" style="margin: 0;font-weight: bold;">
<input class="switch-input" type="checkbox" id="check_'+id+'" />
<span class="switch-label" data-on="Published" data-off="Hidden">  </span> 
<span class="switch-handle"></span>
</label>

我想禁用输入按钮。

1 个答案:

答案 0 :(得分:0)

如果您想默认禁用该按钮,那么

<input class="switch-input" type="checkbox" id="check_'+id+'" disabled/>

如果你想在jquery

中的某些动作上禁用按钮
$(function(){
   $('#SomeButton').on('click', function(){
        $('#your_input_id').attr('disabled' , 'disabled') //OR
        $('#your_input_id').prop('disabled' , true) //true for disabled, false to enable
   });
});

或者,如果您希望在页面加载时默认禁用而不执行任何操作

$(function(){
        $('#your_input_id').attr('disabled' , 'disabled') //OR
        $('#your_input_id').prop('disabled' , true) //true for disabled, false to enable
});