您好我正在使用iCheck(http://icheck.fronteed.com/
问题是,当我单击复选框时,输入文件按钮可以工作,但似乎被“禁用”,但它仍然是灰色,而不是绿色。

我正在使用两个事件,ifChecked / ifUnchecked。

我尝试使用attrremoveclassaddclass,而不是使用.prop()

<input id="Archivo" name="Archivo" type="file" accept=".pdf,.doc" disabled />

 $("#Archivo").fileinput({
    language: "es",
    browseClass: "btn btn-primary",
    showCaption: true,
    showRemove: false,
    showUpload: false,
    browseLabel: "&nbsp;Buscar",
    allowedFileExtensions: ["pdf", "doc"],
    elErrorContainer: "#divErrorImagen",
    maxFileSize: 122880
});


$('input').on('ifChecked', function (event) {
    console.log("Checked OK")
   $('#Archivo').prop("disabled", false);


});
$('input').on('ifUnchecked', function (event) {
    console.log("Unchecked OK")
   $('#Archivo').prop("disabled", true);

});

最佳答案

尝试使用fileinput插件disableenable方法



$(document).ready(function() {
  $("#Archivo").fileinput({
    language: "es",
    browseClass: "btn btn-primary",
    showCaption: true,
    showRemove: false,
    showUpload: false,
    browseLabel: "&nbsp;Buscar",
    allowedFileExtensions: ["pdf", "doc"],
    elErrorContainer: "#divErrorImagen",
    maxFileSize: 122880
  });

  $('#checkbox').iCheck({
    checkboxClass: 'icheckbox_minimal',
    radioClass: 'iradio_minimal',
    increaseArea: '20%'
  });

  $('input').on('ifChecked', function(event) {
    console.log("Checked OK")
    $('#Archivo').fileinput('disable');
  });

  $('input').on('ifUnchecked', function(event) {
    console.log("Unchecked OK")
    $('#Archivo').fileinput('enable');
  });
});

<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>

<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/iCheck/1.0.2/skins/all.css" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/iCheck/1.0.2/icheck.min.js"></script>

<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-fileinput/4.5.3/css/fileinput.css" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-fileinput/4.5.3/js/fileinput.js"></script>

<input id="Archivo" name="Archivo" type="file" accept=".pdf,.doc" disabled />

<input type="checkbox" id="checkbox">

10-08 13:18