第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

如何進(jìn)行拖放?

如何進(jìn)行拖放?

慕運(yùn)維8079593 2022-05-22 10:10:09
只是一個(gè)簡(jiǎn)單的拖放不起作用!?。。。?!我使用了另一個(gè)堆棧溢出帖子中的拖放代碼。我試圖讓文件在被刪除時(shí)進(jìn)入文件輸入。其他代碼主要是風(fēng)格/或用于顯示文件名。<!DOCTYPE html><html><head>    <link href="style.css" rel="stylesheet">    <meta charset="UTF-8">    <meta name="viewport" content="width=device-width, initial-scale=1.0">    <title>File Upload</title></head><body>    <div id="dropContainer">        Drag and drop a file        <br>        or        <br>        <input type="file" id="fileInput" hidden="hidden" />        <button id="fakeButton">Select a file</button>        <span id="fileText">No file Selected</span>    </div>    <script>        const dropContainer = document.getElementById("dropContainer");        const fileInput = document.getElementById("fileInput");        const fakeButton = document.getElementById("fakeButton");        const fileText = document.getElementById("fileText");        fakeButton.addEventListener("click", () => {            fileInput.click();        });        // dragover and dragenter events need to have 'preventDefault' called        // in order for the 'drop' event to register.         // See: https://developer.mozilla.org/en-US/docs/Web/Guide/HTML/Drag_operations#droptargets        dropContainer.ondragover = dropContainer.ondragenter = function (evt) {            evt.preventDefault();        };        dropContainer.ondrop = function (evt) {            // pretty simple -- but not for IE :(            fileInput.files = evt.dataTransfer.files;            // If you want to use some of the dropped files            const dT = new DataTransfer();            dT.items.add(evt.dataTransfer.files[0]);            dT.items.add(evt.dataTransfer.files[3]);            fileInput.files = dT.files;            evt.preventDefault();        };
查看完整描述

1 回答

?
12345678_0001

TA貢獻(xiàn)1802條經(jīng)驗(yàn) 獲得超5個(gè)贊

問(wèn)題是當(dāng)您在放置事件中分配文件時(shí),文件輸入上的事件偵聽(tīng)器不會(huì)觸發(fā)。fileInput.addEventListener("change", () => {


將該代碼嵌入到函數(shù)中,您可以在ondrop事件結(jié)束時(shí)調(diào)用它來(lái)完成預(yù)期的行為。


const dropContainer = document.getElementById("dropContainer");

const fileInput = document.getElementById("fileInput");

const fakeButton = document.getElementById("fakeButton");

const fileText = document.getElementById("fileText");


function SetFileName() {

    if (fileInput.value) {

        fileText.innerHTML = fileInput.value.match(/[\/\\]([\w\d\s\.\-\(\)]+)$/)[1];

    } else {

        fileText.innerHTML = "no file selected";

    }

};


fakeButton.addEventListener("click", () => {

    fileInput.click();

});


// dragover and dragenter events need to have 'preventDefault' called

// in order for the 'drop' event to register. 

// See: https://developer.mozilla.org/en-US/docs/Web/Guide/HTML/Drag_operations#droptargets

dropContainer.ondragover = dropContainer.ondragenter = function(evt) {

    evt.preventDefault();

};


dropContainer.ondrop = function(evt) {

    // pretty simple -- but not for IE :(

    fileInput.files = evt.dataTransfer.files;


    // If you want to use some of the dropped files

    const dT = new DataTransfer();

    dT.items.add(evt.dataTransfer.files[0]);

    fileInput.files = dT.files;


    SetFileName()

};

<!DOCTYPE html>

<html>


<head>

    <link href="style.css" rel="stylesheet">

    <meta charset="UTF-8">

    <meta name="viewport" content="width=device-width, initial-scale=1.0">

    <title>File Upload</title>

</head>


<body>

    <div id="dropContainer">

        Drag and drop a file

        <br>

        or

        <br>

        <input type="file" id="fileInput" hidden="hidden" />

        <button id="fakeButton">Select a file</button>

        <span id="fileText">No file Selected</span>

    </div>


</body>


</html>


查看完整回答
反對(duì) 回復(fù) 2022-05-22
  • 1 回答
  • 0 關(guān)注
  • 116 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)