<!doctype HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "http://www.w3.org/tr/xhtml1/dtd/ Xhtml1-transitional.dtd ">
<meta http-equiv= "Content-type" content= "text/html; charset=gb2312 "/>
<title>jquery image Upload </title>
<script language= "Web Effects" >
Preview image
(function ($) {
$.fn.previewimage = function (options) {
var default = {
Imageclientid: "",
MAXWIDTH:300,
maxheight:300
};
$.extend (True, default, options);
Return This.each (function () {
if (Default.imageclientid!= "") {
$ (this). Unbind ("Change");
$ (this). Change (function () {
if ($ (this). val () = "") {
$ ("#" + Default.imageclientid). Parent ("div"). Hide ();
Return
}
else {
$ ("#" + Default.imageclientid). Parent ("Div"). Show ();
}
if ($.browser.msie) {
$ ("#" + Default.imageclientid). attr ("src", $ (this). Val ());
}
else {
$ ("#" + Default.imageclientid). attr ("src", $ (this) [0].files[0].getasdataurl ());
}
if ($.browser.msie && $.browser.version > 6) {
$ ("#" + Default.imageclientid). Hide ();
$ ("#" + Default.imageclientid). Parent ("div"). CSS tutorial ({' Z-index ': ' 999 ',
' Filter ': ' Progid:dximagetransform.microsoft.alphaimageloader (Sizingmethod=scale) ',
' Max-width ': Default.maxwidth + ' px ', ' max-height ': Default.maxheight + ' px ',
' Width ': default.maxwidth + ' px ', ' height ': default.maxheight + ' px '
});
var div = $ ("#" + Default.imageclientid). Parent ("div") [0];
Div.filters.item ("Dximagetransform.microsoft.alphaimageloader"). src = $ ("#" + Default.imageclientid). attr ("src");
}
});
$ ("#" + Default.imageclientid). Load (function () {
var image = new Image ();
IMAGE.SRC = $ (this). attr ("src");
$ (this). attr ("width", default.maxwidth);
$ (this). attr ("height", default.maxheight);
$ (this). attr ("alt", Default.maxwidth + "x" + default.maxheight);
});
}
});
};
}) (jquery);
</script>
<body>
<asp Tutorial: FileUpload id= "fileupload_1" runat= "Server"/>
$ ("#<%=fileupload_1.clientid%>"). Previewimage ({imageclientid: "Uploadimage", MaxWidth: "425", MaxHeight: "200 " });
</body>
Picture Upload Preview Plugin Two
Preview image
(function ($) {
$.fn.previewimage = function (options) {
var default = {
Imageclientid: "",
MAXWIDTH:300,
maxheight:300
};
$.extend (True, default, options);
Return This.each (function () {
if (Default.imageclientid!= "") {
$ (this). Unbind ("Change");
$ (this). Change (function () {
if ($ (this). val () = "") {
$ ("#" + Default.imageclientid). Parent ("div"). Hide ();
Return
}
else {
$ ("#" + Default.imageclientid). Parent ("Div"). Show ();
}
if ($.browser.msie) {
$ ("#" + Default.imageclientid). attr ("src", $ (this). Val ());
}
else {
$ ("#" + Default.imageclientid). attr ("src", $ (this) [0].files[0].getasdataurl ());
}
if ($.browser.msie && $.browser.version > 6) {
$ ("#" + Default.imageclientid). Hide ();
$ ("#" + Default.imageclientid). Parent ("div"). css ({' Z-index ': ' 999 ',
' Filter ': ' Progid:dximagetransform.microsoft.alphaimageloader (Sizingmethod=scale) ',
' Max-width ': Default.maxwidth + ' px ', ' max-height ': Default.maxheight + ' px ',
' Width ': default.maxwidth + ' px ', ' height ': default.maxheight + ' px '
});
var div = $ ("#" + Default.imageclientid). Parent ("div") [0];
Div.filters.item ("Dximagetransform.microsoft.alphaimageloader"). src = $ ("#" + Default.imageclientid). attr ("src");
}
});
$ ("#" + Default.imageclientid). Load (function () {
var image = new Image ();
IMAGE.SRC = $ (this). attr ("src");
$ (this). attr ("width", default.maxwidth);
$ (this). attr ("height", default.maxheight);
$ (this). attr ("alt", Default.maxwidth + "x" + default.maxheight);
});
}
});
};
}) (jquery);
Use a div outside the IMG (compatible IE7,IE8, for filter dximagetransform.microsoft.alphaimageloader)
For example:
Control
: <asp:fileupload id= "FileUpload1" runat= "server"/>
<br/>
<div Style= "Display:none;" >
</div>
jquery Code: $ (document). Ready (function () {
$ ("#<%= Fileupload1.clientid%> "). Previewimage ({imageclientid:" Uploadimage ", MaxWidth:" $ ", MaxHeight:" 500 "});
});