<input id="text" type="text">
<script>
$('#text')[0].addEventListener('paste', function(e) {
var cb = e.clipboardData.items;
for(var i=0; i < cb.length; i++) {
if (cb[i].kind != 'file' && cb[i].type.indexOf('image') < 0) return;
var file = cb[i].getAsFile();
var formData = new FormData();
formData.append('file', file);
$.ajax({
url : 'upload',
type : 'POST',
data : formData,
contentType: false,
processData: false,
dataType: 'json',
clearForm: true,
success: function(data) {
if (data.result === "OK") {
Toast('上传成功: ' + data.url, 5000);
} else {
Toast('上传失败:<br/>' + data.msg, 5000);
}
},
error: function(data, status, e) {
Toast('上传失败:<br/>' + e, 5000);
}
});
e.preventDefault();
}
});
</script>