To develop “BufPay.com personal instant payment platform”, the background needs to support developers’ wechat and Alipay QR code uploading.

<p>
<button class="btn btn-primary" onClick="javascript:document.getElementById('fileupload').click();">Upload qr codes of wechat/Alipay payment in batches</button>
<input style="display:none;" id="fileupload" type="file" name="file" accept="image/*" multiple>
</p>Copy the code

The original way is to click on the button to trigger a hidden file onchange event, thus popup the file selection box, select the file.

But there is user feedback directly drag the two-dimensional code into the collection will be more convenient. So, modify the original code and add it to the JS file

<p id="drop_area" onClick="javascript:document.getElementById('fileupload').click();">
<button class="btn btn-primary"< p style= "max-width: 100%; clear: both; min-height: 1em"display:none;" id="fileupload" type="file" name="file" accept="image/*" multiple>
</p>Copy the code

    var dp = document.getElementById('drop_area');
    dp.addEventListener('dragover'.function(e) {
        e.stopPropagation();
        e.preventDefault();
        e.dataTransfer.dropEffect = 'copy';
    });
    dp.addEventListener("drop".function(e) {
        e.stopPropagation();
        e.preventDefault();
        var files = e.dataTransfer.files;
        // do something upload
    });Copy the code

Add the upper level p of the button as a drop area to monitor the dragover and drop events, and perform operations on the dragged file in the drop event.


Advertisement ✧(≖ plus-one item ≖✿