CSS代码:
.clip { position: absolute; clip: rect(0 0 0 0); }
HTML代码:
<input type="file" id="uploadFile" class="clip" accept="image/*"> <label class="ui-button ui-button-primary" for="uploadFile">选择图片</label> <img id="imgCover" src="./watermark.png" class="clip"> <p id="imgUploadX"></p>
JS代码:
var eleUploadFile = document.getElementById('uploadFile'); var eleImgCover = document.getElementById('imgCover'); var eleImgUploadX = document.getElementById('imgUploadX'); if (history.pushState) { eleUploadFile.addEventListener('change', function (event) { var reader = new FileReader(); var file = event.target.files[0] || event.dataTransfer.files[0]; reader.onload = function(e) { var base64 = e.target.result; if (base64.length > 1024 * 50) { alert('图片尺寸请小于50K'); return; } else {