Strange behavior with click event on button?

前端 未结 2 1441
灰色年华
灰色年华 2021-01-26 06:40

I am using jQuery File Upload plugin here for uploading files.

For each file that is added I generate a row in the table with a hidden button (that would be the single u

2条回答
  •  轮回少年
    2021-01-26 07:07

    The following code binds the event to all buttons with the name "singleUploadFile".

    $('button[name="singleUploadFile"]').click(function () {
       if (data.files.length > 0) {
           data.submit();
           addedFiles += 1;
       }
    });
    

    But you want it to bind the event just to the newly added button (not to buttons that already have it bound).

    Do the following:

    data.context.find('button[name="singleUploadFile"]').click(function () {
       if (data.files.length > 0) {
           data.submit();
           addedFiles += 1;
       }
    });
    

提交回复
热议问题