js上传头像预览
//html
<a href="#" class="fiinput"><img src="./../images/images@2x.png" id="ImgPr" alt=""> <input type="file" class="files" ></a>
//js
$(".files").change(function() {
var $file = $(this);
var fileObj = $file[0];
var windowURL = window.URL || window.webkitURL;
var dataURL;
var $img = $("#ImgPr");
if(fileObj && fileObj.files && fileObj.files[0]){
dataURL = windowURL.createObjectURL(fileObj.files[0]);
console.log(dataURL)
$img.attr('src',dataURL);
}else{
dataURL = $file.val();
var imgObj = document.getElementById("ImgPr");
imgObj.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(sizingMethod=scale)";
imgObj.filters.item("DXImageTransform.Microsoft.AlphaImageLoader").src = dataURL;
console.log( imgObj.filters.item("DXImageTransform.Microsoft.AlphaImageLoader").src = dataURL)
}
})
//判断移动端pc端跳转适配
!function(o){var a=window.location.hash;"#pc"!=a&&/iphone|ipod|ipad|ipad|Android|nokia|blackberry|webos|webos|webmate|bada|lg|ucweb|skyfire|sony|ericsson|mot|samsung|sgh|lg|philips|panasonic|alcatel|lenovo|cldc|midp|wap|mobile/i.test(navigator.userAgent.toLowerCase())&&(o.location.href="http://m.mokuge.com/")}(window);
网友评论