亚洲国产日韩欧美一区二区三区,精品亚洲国产成人av在线,国产99视频精品免视看7,99国产精品久久久久久久成人热,欧美日韩亚洲国产综合乱

javascript - Paste a piece of content with pictures and text. How to use js to get the picture and upload it to the server?
扔個(gè)三星炸死你
扔個(gè)三星炸死你 2017-06-24 09:43:22
0
1
1433

You need to paste a piece of content with text and pictures, but the pictures need to be uploaded to the server separately. How to select the pictures from the pasted content. .

扔個(gè)三星炸死你
扔個(gè)三星炸死你

reply all(1)
小葫蘆

General idea:

  1. Listen to onpaste event

  2. Get the clipboard data event.clipboardData through the event parameter in the event callback (not supported by all browsers)

    // '/image/.test(event.clipboardData.types)' // 檢查是否為圖片
    
    // 獲取圖片二進(jìn)制數(shù)據(jù)(似乎瀏覽器的實(shí)現(xiàn)都會(huì)有大小差異)
    Array.each(event.clipboardData.items, function(item){
    if (/image/.test(item.type)) {
    var blob = item.getAsFile();
    var URL = window.URL || window.webkitURL;
    var source = URL.createObjectURL(blob);
    console.log(source) 
    }
    });
  3. Send data to the backend server through Ajax. After the backend stores the image, it returns an accessible address of the image

  4. Visit this address to see the pictures

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template