码迷,mamicode.com
首页 > Web开发 > 详细

js上传展示本地图片

时间:2018-02-12 11:21:50      阅读:171      评论:0      收藏:0      [点我收藏+]

标签:key   java   val   rom   item   data   index   asc   请求   

请求的Js:

<script type="text/javascript">
$(function () {
$(‘#<?php echo $k; ?>‘).change(function () {
var url = getFileUrl(‘<?php echo $k; ?>‘);
if(url == ‘‘){
$(‘#<?php echo $k; ?>_img‘).css(‘display‘,‘none‘);
}else{
$(‘#<?php echo $k; ?>_img‘).attr(‘src‘,url).css(‘display‘,‘‘);
$(‘#<?php echo $k; ?>_err‘).html(‘‘);
}
});
})
function getFileUrl(sourceId) {
var url;
if (navigator.userAgent.indexOf("MSIE")>=1) { // IE
url = document.getElementById(sourceId).value;
} else if(navigator.userAgent.indexOf("Firefox")>0) { // Firefox
url = window.URL.createObjectURL(document.getElementById(sourceId).files.item(0));
} else if(navigator.userAgent.indexOf("Chrome")>0) { // Chrome
url = window.URL.createObjectURL(document.getElementById(sourceId).files.item(0));
}else{
url = window.URL.createObjectURL(document.getElementById(sourceId).files.item(0));
}
return url;
}
</script>

<form action="/mobile/my_order_controller/do_trademark_operation" method="post" id="form" enctype="multipart/form-data" onkeydown="if(event.keyCode==13)return false;"></form>

后端处理:
通过 $_FILES 接收存储图片

js上传展示本地图片

标签:key   java   val   rom   item   data   index   asc   请求   

原文地址:https://www.cnblogs.com/xiamibk/p/8443687.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!