编辑框粘贴截图

<div class="box" contenteditable="true">paste hear</div>

  

<script>
   	var obj = $('.box')[0];
   	obj.onpaste = function (e){
        var items = e.clipboardData.items;
        for (var i = 0; i < items.length; ++i) {
            if (items[i].kind == 'file' &&
                items[i].type.indexOf('image/') !== -1) {
                var blob = items[i].getAsFile();
                window.URL = window.URL || window.webkitURL;
                var blobUrl = window.URL.createObjectURL(blob);
                var img = document.createElement('img');
                img.src = blobUrl;
                var logBox = $(this);
                logBox.append(img);
            }
        }
    }    
</script>

  

posted @ 2015-07-31 14:19  幹掉上帝  阅读(205)  评论(0编辑  收藏  举报