Current position: home page > Website Design >How to normally use webuploader to upload plug-ins in the pop-up window of the bootstrap mode box

How to normally use webuploader to upload plug-ins in the pop-up window of the bootstrap mode box

Author: blueleaf Classification: Website Design Time: January 15, 2024 Browse: 398

In today's work, I encountered a difficult problem. When the company's back-end colleagues used the bootstrap modal box and combined WebUploader to implement the background file upload function, they found that clicking the upload button was invalid. Colleagues asked me for help. After some research, I found three solutions and deeply analyzed their solutions.

 How to normally use webuploader to upload plugin.png in the pop-up window of the bootstrap mode box

First of all, let's explore the core of this problem: Why is it that there is a problem when the upload control is placed in the modal box, but everything is normal when it is placed in a normal DOM element? I guess the problem originates from the fact that the initial state of the DOM structure of the modal box is a hidden element, and its display attribute is none. When JavaScript code is executed on an element whose display attribute is none, the code will not take effect. Therefore, to solve this problem, we need to ensure that the modal box is rendered and its corresponding DOM nodes are loaded on the page, and then re execute the JavaScript code of the uploaded control.

Based on this idea, I propose the following three solutions:

1. Using uploader.refresh(); After the modal box is loaded, execute this function. The example code is as follows.

 $(‘#myModal‘).on(‘shown.bs.modal‘, function () { //The method of executing the redraw button after the modal box is loaded. uploader.refresh(); });

2. After loading the modal box, redraw the button. The example code is as follows.

 function create_Upbox(){ uploader.addButton({ id: '#picker', InnerHTML: 'Select file' }); } $('#myModal').on('shown.bs.modal', function () { create_Upbox(); });

3. After the modal box pop-up window is executed, execute the upload control button Js code , the example code is as follows.

 $('#myModal').on('hide.bs.modal', function () { uploader.destroy(); });

Disclaimer:

Website: Click Copy to share with friends!

All content resources shared by this website, if not noted, are original by Blueleaf. If you need to reprint, please indicate the source; Please contact us in case of infringement Contact handling Please understand!

Comment List
 blink the eyes kiss Growl happy think poor It's embarrassing Grievance ha-ha hush Right hum Zuo Hum Hum doubt A bad laugh Make money Sadness Be cool Seduce fierce handshake yeah Hee hee Shyness applause greedy Madness Embrace gather and watch Mighty awesome
Submit comments

Clear information
Close Comment
music appreciation
Back to top