为什么火狐浏览器无法显示图片??

tongki 2010-12-03 10:24:31
<html>
<head>
<script>
function setimg(path)
{
//alert(path);
document.getElementById("myimg").src=path;
}
</script>
</head>
<body>
<input type="file" onchange="setimg(this.value);">
<div>
<img id="myimg">
</div>
</body>
</html>

以上在IE上可行,但在火狐上则不行!!有何良策?
...全文
1124 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
小辛、 2010-12-03
  • 打赏
  • 举报
回复

(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>
tongki 2010-12-03
  • 打赏
  • 举报
回复
老胡这个可行
Mr-Jee 2010-12-03
  • 打赏
  • 举报
回复
其实
一般情况下 flash插件上传图片、预览、剪裁已经适合高级需求了
普通需求情况下。建议还是考虑下兼容性、方便即可
hch126163 2010-12-03
  • 打赏
  • 举报
回复
我认为最后是预览上传后,服务器的图片!

本地,选择时,window 资源管理器本来就可以预览的
Mr-Jee 2010-12-03
  • 打赏
  • 举报
回复
这在CHROME下也不行的。
hch126163 2010-12-03
  • 打赏
  • 举报
回复


<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>



Mr-Jee 2010-12-03
  • 打赏
  • 举报
回复
我不知道IE为什么可以
但我知道FF下是绝对不允许的~~~
Mr-Jee 2010-12-03
  • 打赏
  • 举报
回复
你想在浏览器显示本地图片?

87,907

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 JavaScript
社区管理员
  • JavaScript
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧