准确的路径都拿不到?
function showPreview(obj) {
var pic=document.getElementById("picid");
var file =obj;
if(window.FileReader){//chrome,firefox7+,opera,IE10+
oFReader = new FileReader();
oFReader.readAsDataURL(file.files[0]);
oFReader.onload = function (oFREvent) {pic.src = oFREvent.target.result;};
}
else if (document.all) {
file.select();
file.blur();
var reallocalpath = document.selection.createRange().text//IE下获取实际的本地文件路径
pic.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(sizingMethod='image',src=\"" + reallocalpath + "\")";
pic.src = 'data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==';
}
else if (file.files) {
if (file.files.item(0)) {
url = file.files.item(0).getAsDataURL();
pic.src=url;
}
}
}
<form>
请选择图片:<input id="myfile" name="myfile" type="file" onchange="showPreview(this);"/>
<div id="previewImg">
<img alt="c" src="" id="picid" width="250" height="200">
</div>
</form>
用什么代码获取的路径都没说