【发布时间】:2019-11-10 12:55:53
【问题描述】:
我有模式,用户可以上传他们的文件。默认情况下,上传按钮被禁用。因此,当用户有插入文件时,应该启用该按钮。但这不会发生。请任何人帮忙。
我也尝试了以下两种方法,但没有帮助。
HTML
<div class="modal-header">
<h4 class="modal-title text-orange2">Upload ES Value File</h4>
<button type="button" class="close" data-dismiss="modal">×</button>
</div>
<form name="esvalueForm" id="esvalueForm" action="" method="POST" enctype="multipart/form-data">
<div class="modal-body">
<div class="pd-20 bg-white border-radius-4">
<div class="row">
<div class="col-lg-12 col-sm-12">
<div class="custom-file">
<input type="file" name="upload_file" id="esvaluefile" class="import-file" accept=".csv">
</div>
</div>
</div>
</div>
</div>
<div class="modal-footer">
<button type="button" id="btnUpload" class="btn btn-primary" data-toggle="modal" data-target="#confirmation-upload" disabled>UPLOAD</button>
</div>
</div>
</div>
</form>
JS(2 种方法)
$("#esvaluefile").change(function() {
if ($("#esvaluefile").val() == "") {
$("#btnUpload").attr('disabled', true);
}
else {
$("#btnUpload").removeAttr("disabled");
}
});
$("#esvaluefile").on('show.bs.modal', function (e) {
if ($("#esvaluefile").val() == "") {
$("#btnUpload").attr('disabled', true);
}
else {
$("#btnUpload").removeAttr("disabled");
}
});
【问题讨论】:
-
试试
$("#btnUpload").attr('disabled', false); -
没有变化
标签: jquery html bootstrap-4 bootstrap-modal