文件上传后更改Asp Button类

时间:2015-11-10 18:07:27

标签: javascript asp.net twitter-bootstrap

我希望在文件上传后启用禁用按钮。但是,我似乎无法启用它。

<asp:Content runat="server" ID="BodyContent" ContentPlaceHolderID="MainContent">
    <script type="text/javascript">
        $('#FileUpload').on('change', function (e) {
            Document.getElementById("btnUploadFile").className = "btn standard-gradient";
        });
    </script>

    <asp:FileUpload ID="FileUpload" runat="server" class="btn"/>

    <asp:Button runat="server" ID="btnUploadFile" Text="Upload File" OnClick="btnUploadFile_OnClick" class="btn standard-gradient disabled"/>
</asp:Content>

1 个答案:

答案 0 :(得分:0)

试试这个脚本:

<script type = "text/javascript" >
    $('#FileUpload').on('change', function (e) {
        var btn = $("#btnUploadFile");
        if (btn.prop("disabled")) { $("#btnUploadFile").prop('disabled', '') } 
        else { $("#btnUploadFile").prop('disabled', 'disabled') }
    });
</script>

将此 JSFIDDLE 作为样本。

<强> HTML

<button id="FileUpload">file</button>
<button id="btnUploadFile">btn</button>

<强> JS

$('#FileUpload').on('click', function (e) {
    var btn = $("#btnUploadFile");
    if ( btn.prop( "disabled" ) ){
        $("#btnUploadFile").prop('disabled', '')
    }
    else {$("#btnUploadFile").prop('disabled', 'disabled')}
});