为什么禁用的属性未在模态中删除?

我有模式,用户可以在其中上传文件。默认情况下,上载按钮处于禁用状态。因此,当用户插入文件时,应启用该按钮。但这不会发生。任何人都可以帮忙。

我还尝试了以下2种方法,但没有帮助。

为什么禁用的属性未在模态中删除?

HTML

<div class="modal-header">
    <h4 class="modal-title text-orange2">Upload ES Value File</h4>
    <button type="button" class="close" data-dismiss="modal">&times;</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");
    }
});
zytzwlj 回答:为什么禁用的属性未在模态中删除?

尝试使用prop()

function toggleUploadButton() {
    $("#btnUpload").prop('disabled',$("#esvaluefile").val() == "");
}
$("#esvaluefile").change(toggleUploadButton)
    .on('show.bs.modal',toggleUploadButton);
本文链接:https://www.f2er.com/3130432.html

大家都在问