网创优客建站品牌官网
为成都网站建设公司企业提供高品质网站建设
热线:028-86922220
成都专业网站建设公司

定制建站费用3500元

符合中小企业对网站设计、功能常规化式的企业展示型网站建设

成都品牌网站建设

品牌网站建设费用6000元

本套餐主要针对企业品牌型网站、中高端设计、前端互动体验...

成都商城网站建设

商城网站建设费用8000元

商城网站建设因基本功能的需求不同费用上面也有很大的差别...

成都微信网站建设

手机微信网站建站3000元

手机微信网站开发、微信官网、微信商城网站...

建站知识

当前位置:首页 > 建站知识

jquery预览图片,jquery实现图片显示

如何用jquery.imgareaselect保存剪切后的预览图像

你的思路应该错了,我给你梳理下吧:

创新互联-云计算及IDC服务提供商,涵盖公有云、IDC机房租用、温江服务器租用、等保安全、私有云建设等企业级互联网基础服务,联系电话:13518219792

用jquery.imgareaselect实际上主要是利用它帮你获得预览图和剪裁数据。然后将数据发送后台根据这些数据就可以从原始图片中重新画出你选择部分的图片信息了。

1,你异步上传后将图片访问路径设置到剪裁区img.src;

2,利用imgareaselect的回调函数拿到图片引用img和选择对象selection,从img拿到引用图片width\height,selection拿到左上角的坐标x1\y1,右下角的坐标x2\y2,选择区宽高width\height。

3,将2中拿到的数据发送到后台,后台根据这些数据和原始图片信息画出选择区的图像。

用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即可。

怎样用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=""

titleDocument/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" /

brbrimg 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

jquery 多图片预览

给你重新写了一个,直接拷贝到记事本另存为html就可以调试(Jquery是在线引用的)。

以下代码在IE8和FF下测试通过。

另:程序如果有什么问题可以HI我。

!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" ""

html

head

title New Document /title

script src="" type="text/javascript"/script

script type="text/javascript"

//全局变量

var FileCount=0;//上传文件总数

//添加上传文件按钮

function addFile(obj)

{

var filePath=$(obj).prev().val();

var FireFoxFileName="";

//FireFox文件的路径需要特殊处理

if(window.navigator.userAgent.indexOf("Firefox")!=-1)

{

FireFoxFileName=filePath;

filePath=$(obj).prev()[0].files.item(0).getAsDataURL();

}

if(!checkFile(filePath,FireFoxFileName))

{

$(obj).prev().val("");

return;

}

if(filePath.length==0)

{

alert("请选择上传文件");

return false;

}

FileCount++;

//添加上传按钮

var html='span';

html+='input id="f'+FileCount+'" name="'+FileCount+'" type="file"/ ';

html+='input type="button" value="添加" onclick="addFile(this)"/';

html+='/span';

$("#fil").append(html);

//添加图片预览

html='li';

html+='img id="img'+(FileCount-1)+'" src="'+filePath+'" width="100" height="100" style="cursor:pointer;" alt="暂无预览" /';

html+='br/';

html+='a href="#" name="img'+(FileCount-1)+'" onclick="DelImg(this)"删除/a';

html+='/li';

$("#ImgList").append(html);

}

//删除上传文件(file以及img)

function DelImg(obj)

{

var ID=$(obj).attr("name");

ID=ID.substr(3,ID.length-3);

$("#f"+ID).parent().remove();

$(obj).parent().remove();

return false;

}

//检查上传文件是否重复,以及扩展名是否符合要求

function checkFile(fileName,FireFoxFileName)

{

var flag=true;

$("#ImgList").find(":img").each(function(){

if(fileName==$(this).attr("src"))

{

flag=false;

if(FireFoxFileName!='')

{

alert('上传文件中已经存在\''+FireFoxFileName+'\'!');

}

else

{

alert('上传文件中已经存在\''+fileName+'\'!');

}

return;

}

});

//文件类型判断

var str="jpg|jpeg|bmp|gif";

var fileExtName=fileName.substring(fileName.indexOf(".")+1);//获取上传文件扩展名

if(FireFoxFileName!='')//fireFox单独处理

{

fileExtName=FireFoxFileName.substring(FireFoxFileName.indexOf(".")+1);

}

//alert(fileExtName);

if(str.indexOf(fileExtName.toLowerCase())==-1)

{

alert("只允许上传格式为jpg,jpeg,bmp,gif的文件。");

flag=false;

}

return flag;

}

/script

style type="text/css"

.fil

{

width:300px;

}

.fieldset_img

{

border:1px solid blue;

width:550px;

height:180px;

text-align:left;

}

.fieldset_img img

{

border:1px solid #ccc;

padding:2px;

margin-left:5px;

}

#ImgList li

{

text-align:center;

list-style:none;

display:block;

float:left;

margin-left:5px;

}

/style

/head

body

p上传预览图片:br

div id="fil" class="fil"

span

input id="f0" name="f0" type="file"/

input type="button" value="添加" onclick="addFile(this)"/

/span

/div

/p

div id="ok"

fieldset class="fieldset_img"

legend图片展示/legend

ul id="ImgList"

!--li

img id="img1" width="100" height="100" style="cursor:pointer;"

br/

a href="#" name="img1" onclick="DelImg(this)"删除/a

/li--

/ul

/fieldset

/div

/body

/html

jQuery File Upload 图片预览代码如何写

jQuery File Upload是上传文件的一个插件,不一定是图片,所以里面没做预览的支持。但是可以直接用jquery简单实现出来,代码如下:

/*

先在js里扩展一个uploadPreview方法

使用方法: 

div

img id="ImgPr" width="120" height="120" //div

input type="file" id="up" /

把需要进行预览的IMG标签外 套一个DIV 然后给上传控件ID给予uploadPreview事件

$("#up").uploadPreview({ Img: "ImgPr", Width: 120, Height: 120, ImgType: ["gif", "jpeg", "jpg", "bmp", "png"], Callback: function () { }});

*/

jQuery.fn.extend({

uploadPreview: function (opts) {

var _self = this,

_this = $(this);

opts = jQuery.extend({

Img: "ImgPr",

Width: 100,

Height: 100,

ImgType: ["gif", "jpeg", "jpg", "bmp", "png"],

Callback: function () {}

}, opts || {});

_self.getObjectURL = function (file) {

var url = null;

if (window.createObjectURL != undefined) {

url = window.createObjectURL(file)

} else if (window.URL != undefined) {

url = window.URL.createObjectURL(file)

} else if (window.webkitURL != undefined) {

url = window.webkitURL.createObjectURL(file)

}

return url

};

_this.change(function () {

if (this.value) {

if (!RegExp("\.(" + opts.ImgType.join("|") + ")$", "i").test(this.value.toLowerCase())) {

alert("选择文件错误,图片类型必须是" + opts.ImgType.join(",") + "中的一种");

this.value = "";

return false

}

if ($.browser.msie) {

try {

$("#" + opts.Img).attr('src', _self.getObjectURL(this.files[0]))

} catch (e) {

var src = "";

var obj = $("#" + opts.Img);

var div = obj.parent("div")[0];

_self.select();

if (top != self) {

window.parent.document.body.focus()

} else {

_self.blur()

}

src = document.selection.createRange().text;

document.selection.empty();

obj.hide();

obj.parent("div").css({

'filter': 'progid:DXImageTransform.Microsoft.AlphaImageLoader(sizingMethod=scale)',

'width': opts.Width + 'px',

'height': opts.Height + 'px'

});

div.filters.item("DXImageTransform.Microsoft.AlphaImageLoader").src = src

}

} else {

$("#" + opts.Img).attr('src', _self.getObjectURL(this.files[0]))

}

opts.Callback()

}

})

}

});

然后是HTML页面进行调用:

!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "

html xmlns="

head

title图片上传预览演示/title

script src="jquery.min.js" type="text/javascript"/script

script src="16/uploadPreview.js" type="text/javascript"/script

script

$(function () {

$("#up").uploadPreview({ Img: "ImgPr", Width: 120, Height: 120 });

});

/script

/head

body

div style="width:500px;margin:0px auto;"h2图片上传预览演示/h2

divimg id="ImgPr" width="120" height="120" //div

input type="file" id="up" /

/div

/body

/html


分享题目:jquery预览图片,jquery实现图片显示
文章链接:http://bjjierui.cn/article/dsgoced.html

其他资讯