jQuery disable/enable submit button

后端 未结 21 3300
难免孤独
难免孤独 2020-11-22 07:30

I have this HTML:



How can I do something li

21条回答
  •  野趣味
    野趣味 (楼主)
    2020-11-22 07:52

    Here's the solution for file input field.

    To disable a submit button for file field when a file is not chosen, then enable after the user chooses a file to upload:

    $(document).ready(function(){
        $("#submitButtonId").attr("disabled", "disabled");
        $("#fileFieldId").change(function(){
            $("#submitButtonId").removeAttr("disabled");
        });
    });
    

    Html:

    <%= form_tag your_method_path, :multipart => true do %><%= file_field_tag :file, :accept => "text/csv", :id => "fileFieldId" %><%= submit_tag "Upload", :id => "submitButtonId" %><% end %>
    

提交回复
热议问题