Home  >  Article  >  Backend Development  >  The change event of type=file can only be executed once and the solution example

The change event of type=file can only be executed once and the solution example

零下一度
零下一度Original
2017-06-23 16:23:361780browse

Recently, when I was helping a friend with a project, I encountered the problem that the type=file change event could only be executed once. After some research, I found that various solutions were provided, so I decided to record my thinking direction and final solution.

                                                                  grant                                      dederation| , why can't it be uploaded? Programmers are all kinds of crazy and anxious, and they start to look for solutions. After searching and searching, they calm down and think of solutions by themselves;

It hurts Design, no matter whether the file upload is successful or not, the added file has been recorded, so the change event will not be executed again. I know the possible reason, let's do it. If I can clear the record, the event Can't it be triggered? I tried it, but it didn't work. Keep looking for a way. What will happen if I replace the tag and then rebind the change event? I tried it and it worked. Here is the code:

< ;form action="/api/Index/Browse" enctype="multipart/form-data" id="form_Upload" method="post">
       

$('input[id=fileUpload]').click( );

var count = 0;
$('input[id=fileUpload]').unbind().change(function () {
$('#form_Upload').ajaxSubmit (options);

});

var options = {
              success: function (data) {
                        //$scope.orderInfo = eval (date); () can only be executed once, replace the control, and rebind the event

                    count++; "file" id="fileUpload" name="file" style="display:none;" title="' + count + '"/>');

                              $('#fileUpload ').on('change', function () {

                                                                                                                                                                    ').on('change', function ()
//End ## Series $http.post (URL, PARAMS) .success (FUNCTION (DATA) {

DO SOMETHING

}, FUNCTION ) { do something
});             });             }
            };

The above is the detailed content of The change event of type=file can only be executed once and the solution example. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn