87,907
社区成员
发帖
与我相关
我的任务
分享
(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);
<div style="display: none; width:167px; height:167px;" >
<img id="uploadimage" src="" /></div>
主题图片无头的:
<asp:FileUpload ID="FileUpload2" runat="server" />
<script>
$(document).ready(function () {
$("#<%=FileUpload1.ClientID %>").PreviewImage({ ImageClientId: "uploadimage", MaxWidth: "167", MaxHeight: "167" });
$("#<%=FileUpload2.ClientID %>").PreviewImage({ ImageClientId: "nohead", MaxWidth: "167", MaxHeight: "167" });
});
</script>
</form>
<input type="file" id="upLoadImgFile" onchange ="setImg()" /><input id="Submit1" type="submit" value="submit" />
<p></p><img src="" id ="imgView" />
<script>
function setImg()
{
var isIE = document.all?true:false;
var isIE7 = isIE && (navigator.userAgent.indexOf('MSIE 7.0') != -1);
var isIE8 = isIE && (navigator.userAgent.indexOf('MSIE 8.0') != -1);
var upLoadImgFile = document.getElementById("upLoadImgFile");
debugger;
var imgView = document.getElementById("imgView");
if(isIE){
if(isIE7 || isIE8)
{
upLoadImgFile.select();
imgView.src = document.selection.createRange().text;
document.selection.empty();
}else{ imgView.src = upLoadImgFile.value;}
}else{
imgView.src = upLoadImgFile.files.item(0).getAsDataURL();
}
}
</script>