我用到的原材料地址:http://www.cnblogs.com/leejersey/p/3660202.html

修改后:

/// <reference path="../../Js/jquery-1.7.2.min.js" />
/*
*使用方法: !!!!!!!!请把input放在图片上方
<div>
<input type="file" id="up" />
<img id="ImgPr" width="120" height="120" /></div>
把需要进行预览的IMG标签外 套一个div 然后给上传控件id给予uploadPreview 然后调用CheckInito 然后点击图片就行了
$("#up").uploadPreview({ Img: "ImgPr", Width: 120, Height: 120, ImgType: ["gif", "jpeg", "jpg", "bmp", "png"], Callback: function () { }}).CheckInito(); var p=$("fff").uploadPreview({});
p.checkFile() //立即弹出file选择文件对话框 ie不适合 */
$.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
}
var ie = navigator.appName == "Microsoft Internet Explorer" ? true : false;
if (ie) {
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()
}
}) return {
/*ie不适用!*/
checkFile: function CheckFile() {
var ie = navigator.appName == "Microsoft Internet Explorer" ? true : false;
if (ie) {
_this[0].click();
} else {
var mouseobj = document.createEvent("MouseEvents");
mouseobj.initEvent("click", true, true);
_this[0].dispatchEvent(mouseobj);
}
return _self;
},
//兼容ie8的
CheckInito: function () {
var ie = navigator.appName == "Microsoft Internet Explorer" ? true : false;
_this.css("position", "absolute");
_this.parent().css("width", opts.Width + "px");
_this.parent().css("height", opts.Height + "px");
if (ie) {
//width: 67.5px; height: 37.4px; padding-right: 5px; position: absolute; opacity: 1;
_this.css("width", opts.Width + "px");
_this.css("height", opts.Height + "px");
_this.css("font-size", "200px");
_this.css("overflow", "hidden");
} else {
_this.css("left", "0px");
_this.css("top", "0px");
_this.css("width", opts.Width + "px");
_this.css("height", opts.Height + "px");
}
_this.css("opacity", "0");
return _self;
}
};
}
});

调用实例:

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title></title>
<script src="Js/jquery-1.7.2.min.js"></script>
<script src="Admin/js/uploadPreview.js"></script>
<script>
function loadOver() {
$("#myselfpicFile").uploadPreview({ Img: "myselfpic", Width: 150, Height: 180 }).CheckInito();
}
</script>
</head>
<body onload="loadOver();">
<div class="photo">
<input id="myselfpicFile" type="file" name="myselfpic" />
<img width="150" height="180" id="myselfpic" class="" src="../$obj.myselfpic" />
</div>
</body>
</html>

最终效果图

ie:

火狐:

谷歌:

请大家多多支持

jquery本地上传预览扩展(隐藏上传控件单击图片上传支持ie!!)的更多相关文章

  1. Asp.net中FileUpload控件实现图片上传并带预览显示

    单一图片上传——“选择”+“上传”,.NET默认模式: 1.实现原理:     采用FileUpload控件默认的使用方式,先由“选择”按钮选择图片,然后单击“上传”按钮完成上传,并可在“上传”按钮的 ...

  2. C# Winform学习---MDI窗体的设计,PictureBox控件(图片上一页下一页),Timer控件,MenuStrip控件

    一.MDI窗体的设计 1.MDI简介 MDI(Multiple Document Interface)就是所谓的多文档界面,与此对应就有单文档界面 (SDI), 它是微软公司从Windows 2.0下 ...

  3. jQuery插件ImgAreaSelect 实例讲解一(头像上传预览和裁剪功能)

    上一节随笔中,我们已经知道了关于jQuery插件ImgAreaSelect基本的知识:那么现在看一下实例: 首先,要知道我们应该实现什么功能? (1)图片能够实现上传预览功能 (2)拖拽裁剪图片,使其 ...

  4. ASP.NET工作笔记之一:图片上传预览及无刷新上传

    转自:http://www.cnblogs.com/sibiyellow/archive/2012/04/27/jqueryformjs.html 最近项目里面涉及到无刷新上传图片的功能,其实也就是上 ...

  5. JQ上传预览+存数据库

    因为之前老师讲的方法有不少BUG 现在经过完善已经修复 之前老是讲的方法是每一张都会被传到后台文件夹里面去 导致在预览过程中如果刷新页面 那么预览的图片不能从后台文件夹中删除  这个方法实现在本地预览 ...

  6. Jquery图片上传预览效果

    uploadPreview.js jQuery.fn.extend({ uploadPreview: function (opts) { var _self = this, _this = $(thi ...

  7. js实现本地的图片压缩上传预览

    js在设计时考虑到安全的原因是不允许读写本地文件的,随着html5的出现提供了fileReader AP从而可以I实现本地图片的读取预览功能, 另外在移动端有的限制图片大小的需求,主要是考虑图片过大会 ...

  8. ux.plup.File plupload 集成 ux.plup.FileLis 批量上传预览

    //plupload 集成 Ext.define('ux.plup.File', { extend: 'Ext.form.field.Text', xtype: 'plupFile', alias: ...

  9. C# MVC(File)控件多张图片上传加预览

    刚来公司实习,老板叫我写一个积分商城网站.用的是公司的框架结构搭建的后台,所以后台的图片上传不需要自己写.但是前台的评价图片就需要自己手写了,在网上找了很多代码发现都用不了.问了很多人也都没有实现! ...

随机推荐

  1. Cesium应用篇:3控件(3)SelectionIndicator& InfoBox

    假设这样一个场景,用户在Cesium球上加载了一个GeoJson文件(DataSource),里面是全美国所有州的Geometry信息(Entity),叠加到球面后,你自然会有一种冲动,点击某一个州, ...

  2. js实现String.Fomat

    引言 拼接字符串用习惯了C#的String.Format.今天看别人的代码在js中也封装了一个js的String.Format,用来拼接字符串和DOM. js实现和调用String.Format St ...

  3. 【JUC】JDK1.8源码分析之LockSupport(一)

    一.前言 最开始打算分析ReentrantLock,但是分析到最后,发现离不开LockSuport的支持,所以,索性就先开始分析LockSupport,因为它是锁中的基础,是一个提供锁机制的工具类,所 ...

  4. Linux上的SQL Server——预告片

    大家可能都听说了,微软在几个星期前宣布发布可以在Linux上完整运行的SQL Server!如果你想看下在Linux上SQL Server如何运行,进行查询是什么样的体验,可以看下下面的视频.

  5. ASP.NET MVC5中View-Controller间数据的传递

    使用ASP.NET MVC做开发时,经常需要在页面(View)和控制器(Controller)之间传递数据,那么都有哪些数据传递的方式呢? 本文对于View向Controller中传值共列举了以下几种 ...

  6. 在AngularJS中的使用Highcharts图表控件

    一.Highcharts简介 Highcharts是一款非常好用的前端图表控件,正如其中文网介绍的那样:功能强大.开源.美观.图表丰富.兼容绝大多数浏览器的纯js图表库. 如果你的项目是基于jquer ...

  7. 使用nodejs爬取拉勾苏州和上海的.NET职位信息

    最近开始找工作,本人苏州,面了几家都没有结果很是伤心.在拉勾上按照城市苏州关键字.NET来搜索一共才80来个职位,再用薪水一过滤,基本上没几个能投了.再加上最近苏州的房价蹭蹭的长,房贷压力也是非常大, ...

  8. UVALive 6916---Punching Robot(卢卡斯+容斥)

    题目链接 https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_ ...

  9. C++笔记 之 基础回顾(一)

    1  exe 程序

  10. HTML思维导图