标签:sda file this span function ntb index document code
<input id="file" type="file"> <br> <textarea id="imgbase" name="" id="" cols="100" rows="10"></textarea>
js代码:
var file = document.getElementById(‘file‘) file.onchange = function(){ // 获取files对象 var f = this.files[0]; // 判断是否为图片 if (!(f.type.indexOf(‘image‘) == 0 && f.type && /\.(?:jpg|png|gif)$/.test(f.name))){ this.value = null; alert(‘图片只能是jpg,gif,png‘); return; } // 转换 var reader = new FileReader() reader.readAsDataURL(f) reader.onload = function(e){ document.getElementById(‘imgbase‘).value = this.result; }; };
标签:sda file this span function ntb index document code
原文地址:http://www.cnblogs.com/lvyueyang/p/6815858.html