<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上可行,但在火狐上则不行!!有何良策?
<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上可行,但在火狐上则不行!!有何良策?
但我知道FF下是绝对不允许的~~~
<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>
一般情况下 flash插件上传图片、预览、剪裁已经适合高级需求了
普通需求情况下。建议还是考虑下兼容性、方便即可
(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>