当前位置:首页 » 文件管理 » jquery图片上传预览

jquery图片上传预览

发布时间: 2022-08-31 22:23:38

1. 求JS或jquery的上传图片带预览的代码

这里有很多jquery插件,正好有你找的
http://www.jb51.net/article/14805.htm
希望对你有帮助

2. JS怎么实现图片预览效果

//图片上传预览IE是用了滤镜。
functionpreviewImage(file)
{
varMAXWIDTH=260;
varMAXHEIGHT=180;
vardiv=document.getElementById('preview');
if(file.files&&file.files[0])
{
div.innerHTML='<imgid=imghead>';
varimg=document.getElementById('imghead');
img.onload=function(){
varrect=clacImgZoomParam(MAXWIDTH,MAXHEIGHT,img.offsetWidth,img.offsetHeight);
img.width=rect.width;
img.height=rect.height;
//img.style.marginLeft=rect.left+'px';
img.style.marginTop=rect.top+'px';
}
varreader=newFileReader();
reader.onload=function(evt){img.src=evt.target.result;}
reader.readAsDataURL(file.files[0]);
}
else//兼容IE
{
varsFilter='filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(sizingMethod=scale,src="';
file.select();
varsrc=document.selection.createRange().text;
div.innerHTML='<imgid=imghead>';
varimg=document.getElementById('imghead');
img.filters.item('DXImageTransform.Microsoft.AlphaImageLoader').src=src;
varrect=clacImgZoomParam(MAXWIDTH,MAXHEIGHT,img.offsetWidth,img.offsetHeight);
status=('rect:'+rect.top+','+rect.left+','+rect.width+','+rect.height);
div.innerHTML="<divid=divheadstyle='width:"+rect.width+"px;height:"+rect.height+"px;margin-top:"+rect.top+"px;"+sFilter+src+""'></div>";
}
}
functionclacImgZoomParam(maxWidth,maxHeight,width,height){
varparam={top:0,left:0,width:width,height:height};
if(width>maxWidth||height>maxHeight)
{
rateWidth=width/maxWidth;
rateHeight=height/maxHeight;

if(rateWidth>rateHeight)
{
param.width=maxWidth;
param.height=Math.round(height/rateWidth);
}else
{
param.width=Math.round(width/rateHeight);
param.height=maxHeight;
}
}

param.left=Math.round((maxWidth-param.width)/2);
param.top=Math.round((maxHeight-param.height)/2);
returnparam;

3. 我需要一个js或者jquery能批量上传图片+预览的功能。急~~~急~~~急~~

WebUploader项目,符合你的要求。

//文件上传过程中创建进度条实时显示。
uploader.on('uploadProgress',function(file,percentage){
var$li=$('#'+file.id),
$percent=$li.find('.progressspan');

//避免重复创建
if(!$percent.length){
$percent=$('<pclass="progress"><span></span></p>')
.appendTo($li)
.find('span');
}

$percent.css('width',percentage*100+'%');
});
//文件上传成功,给item添加成功class,用样式标记上传成功。
uploader.on('uploadSuccess',function(file){
$('#'+file.id).addClass('upload-state-done');
});

//文件上传失败,显示上传出错。
uploader.on('uploadError',function(file){
var$li=$('#'+file.id),
$error=$li.find('div.error');

//避免重复创建
if(!$error.length){
$error=$('<divclass="error"></div>').appendTo($li);
}

$error.text('上传失败');
});

//完成上传完了,成功或者失败,先删除进度条。
uploader.on('uploadComplete',function(file){
$('#'+file.id).find('.progress').remove();
});

更多细节,请查看js源码

4. js/jquery如何实现一张图片的上传预览功能。。。。

使用AJAX,把文件保存到临时目录,把返回的值(文件路径),放到页面上预先添加的<IMG> 标签中,就可显示预览图片,再点上传才把文件从临时目录(删除临时目录文件)复制到你指定的目录中

5. 上传照片,并且马上能预览到缩略图,这用的是哪个js插件

无需插件:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>By:DragonDean</title>
<script type="text/javascript">
//下面用于图片上传预览功能
function setImagePreview(avalue) {
var docObj=document.getElementById("doc");

var imgObjPreview=document.getElementById("preview");
if(docObj.files &&docObj.files[0])
{
//火狐下,直接设img属性
imgObjPreview.style.display = 'block';
imgObjPreview.style.width = '150px';
imgObjPreview.style.height = '180px';
//imgObjPreview.src = docObj.files[0].getAsDataURL();

//火狐7以上版本不能用上面的getAsDataURL()方式获取,需要一下方式
imgObjPreview.src = window.URL.createObjectURL(docObj.files[0]);
}
else
{
//IE下,使用滤镜
docObj.select();
var imgSrc = document.selection.createRange().text;
var localImagId = document.getElementById("localImag");
//必须设置初始大小
localImagId.style.width = "150px";
localImagId.style.height = "180px";
//图片异常的捕捉,防止用户修改后缀来伪造图片
try{
localImagId.style.filter="progid:DXImageTransform.Microsoft.AlphaImageLoader(sizingMethod=scale)";
localImagId.filters.item("DXImageTransform.Microsoft.AlphaImageLoader").src = imgSrc;
}
catch(e)
{
alert("您上传的图片格式不正确,请重新选择!");
return false;
}
imgObjPreview.style.display = 'none';
document.selection.empty();
}
return true;
}

</script>
</head>

<body>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td height="101" align="center">
<div id="localImag"><img id="preview" src="http://blog.chuangling.net/Public/images/top.jpg" width="150" height="180" style="display: block; width: 150px; height: 180px;"></div>
</td>
</tr>
<tr>
<td align="center" style="padding-top:10px;"><input type="file" name="file" id="doc" style="width:150px;" onchange="javascript:setImagePreview();"></td>
</tr>
</tbody>
</table>
</body>
</html>

6. JS 显示 上传 图片 ,,高手帮我解释一下这段代码

浏览器安全性已经大大提高,要实现图片上传预览不是那么简单了

不过有很多变通或先进的方法来实现

例如ie7/ie8的滤镜预览法,firefox3的getAsDataURL方法

具体可以参考这个图片上传预览效果

7. 怎样用js或者jq实现点击这个图片就可以选择上传还有预览图片啊

<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<meta name="Generator" content="EditPlus®">
<meta name="Author" content="">
<meta name="Keywords" content="">
<meta name="Description" content="">
<title>Document</title>
<script src="jquery-3.1.1.min.js"></script>
</head>
<body>
<h3>请选择图片文件:JPG/GIF</h3>
<form name="form0" id="form0" >
<input type="file" name="file0" id="file0" multiple="multiple" />
<br><br><img src="" id="img0" width="120">
</form>
</body>
<script>
$("#file0").change(function(){
var objUrl = getObjectURL(this.files[0]) ;
console.log("objUrl = "+objUrl) ;
if (objUrl)
{
$("#img0").attr("src", objUrl);
$("#img0").removeClass("hide");
}
}) ;
//建立一个可存取到该file的url
function getObjectURL(file)
{
var url = null ;
if (window.createObjectURL!=undefined)
{ // basic
url = window.createObjectURL(file) ;
}
else if (window.URL!=undefined)
{
// mozilla(firefox)
url = window.URL.createObjectURL(file) ;
}
else if (window.webkitURL!=undefined) {
// webkit or chrome
url = window.webkitURL.createObjectURL(file) ;
}
return url ;
}
$('input').on('change',function(){
var value = $(this).val();
value = value.split("\\")[2];
alert(value);
})
</script>
</html>

8. 用JS或者JQ写多个点击预览和点击上传功能,点击预览会弹出一个遮罩层来显示图片

.onwindow{
position:fixed;
top:43%;
left:43%;
z-index:99;
width:250px;
height:135px;
background-color:rgba(255,255,255,1);
display:none;
border:2pxsolidred;
border-radius:15px;
padding:10px;
}

.plank{
position:fixed;
top:0;
bottom:0;
left:0;
right:0;
background-color:rgba(255,255,255,0.8);
width:100%;
display:none;
}
<divclass="onwindow">//显示窗口
<image>...........
</div>
<divclass="plank"></div>//背景
varhide=()=>{$(".onwindow").hide();$(".plank").hide();}
varshow=()=>{$(".onwindow").show();$(".plank").show();}

9. 用js、jquery如何实现上传图片的预览

$("#btnLoadPhoto").upload({ url: "../UploadForms/RequestUpload.aspx?action=photo", type: "json", callback: calla });
//获得表单元素
HttpPostedFile oFile = context.Request.Files[0];
//设置上传路径
string strUploadPath = "temp/";
//获取文件名称
string fileName = context.Request.Files[0].FileName;
补充:JQuery是继prototype之后又一个优秀的Javascript库。它是轻量级的js库 ,它兼容CSS3,还兼容各种浏览器(IE 6.0+, FF 1.5+, Safari 2.0+, Opera 9.0+),jQuery2.0及后续版本将不再支持IE6/7/8浏览器。jQuery使用户能更方便地处理HTML(标准通用标记语言下的一个应用)、events、实现动画效果,并且方便地为网站提供AJAX交互。jQuery还有一个比较大的优势是,它的文档说明很全,而且各种应用也说得很详细,同时还有许多成熟的插件可供选择。jQuery能够使用户的html页面保持代码和html内容分离,也就是说,不用再在html里面插入一堆js来调用命令了,只需要定义id即可。

热点内容
o2o生活源码 发布:2024-10-12 19:14:40 浏览:783
电脑硬件配置是什么 发布:2024-10-12 18:33:58 浏览:257
菏泽科二预约密码是多少 发布:2024-10-12 18:33:55 浏览:67
找零点C语言 发布:2024-10-12 18:33:42 浏览:190
快手怎么上传gif 发布:2024-10-12 18:15:02 浏览:513
ctr算法 发布:2024-10-12 18:13:32 浏览:246
如何创建服务器账号 发布:2024-10-12 18:13:19 浏览:724
物理存储是指闪存吗 发布:2024-10-12 18:00:21 浏览:542
怎么看bcg是否配置到vs里 发布:2024-10-12 17:53:54 浏览:732
linux下sql 发布:2024-10-12 17:19:34 浏览:115