国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 網站 > WEB開發 > 正文

jquery本地上傳預覽擴展(隱藏上傳控件單擊圖片上傳支持ie!!)

2024-04-27 15:01:54
字體:
來源:轉載
供稿:網友

我用到的原材料地址: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="Img*/$.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:

 

火狐:

 

谷歌:

 

 

請大家多多支持


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 甘谷县| 蓬莱市| 乐山市| 平南县| 湛江市| 内江市| 呈贡县| 平潭县| 兴化市| 九江市| 彝良县| 陕西省| 拉孜县| 肇东市| 银川市| 怀化市| 那坡县| 福泉市| 清丰县| 山阳县| 万山特区| 泰顺县| 土默特左旗| 抚州市| 偏关县| 文成县| 东阿县| 静海县| 江川县| 噶尔县| 商南县| 怀远县| 鄂州市| 中卫市| 天等县| 大英县| 深州市| 漠河县| 新闻| 昭觉县| 石台县|