php图片预览问题

kuailelj 2011-10-12 09:46:03
<head>
<meta http-equiv="content-type" content="text/html; charset=gb2312" />
<title>网页特效 上传图片预览</title>
<script language="网页特效">
function showimage(fileuploadid, imgid) {
if (document.getelementbyid(fileuploadid).value != "") {
document.getelementbyid(imgid).style.display = "block"
document.getelementbyid(imgid).src = getpath(document.getelementbyid(fileuploadid));
}
}

function getpath(obj) {
if (obj) {
if (window.navigator.useragent.indexof("msie") >= 1) {
obj.select(); return document.selection.createrange().text;
}
else if (window.navigator.useragent.indexof("firefox") >= 1) {
if (obj.files) { return obj.files.item(0).getasdataurl(); }
return obj.value;
}
return obj.value;
}
}

</script>
</head>

<body>
<form enctype="multipart/form-data">
<label>
<input type="file" name="file" id="fid" onmouseo教程ut="showimage('fid','viewimg');">
</label>
<input name="" type="button" value="提交">
</form>
<img src="" id="viewimg">
</div>
</body>
</html>
这里的onmouseo教程ut是什么意思?
...全文
253 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
kuailelj 2011-10-13
  • 打赏
  • 举报
回复
现在知道为什么IE不能正常显示图片。是因为IE7/8都不能直接使用本地路径显示图片。那我应该怎样改呢(滤镜)
kuailelj 2011-10-12
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 sink 的回复:]
这样试试


HTML code


<table>
<tr>
<td colspan='2'>
<input type="file" name="link_pic" class="fl file_input" id="tupian" />
<input type="button" class="upload_btn fl" value="上传" onc……
[/Quote]
还是不行
sink 2011-10-12
  • 打赏
  • 举报
回复
这样试试


<table>
<tr>
<td colspan='2'>
<input type="file" name="link_pic" class="fl file_input" id="tupian" />
<input type="button" class="upload_btn fl" value="上传" onclick="yulan2('tupian');" />
</td>
</tr>
<tr style="display:none" id="image">
<td width="100px">  图片预览</td>
<td><div id="image2"></div></td>
</tr>
</table>
<SCRIPT LANGUAGE="JavaScript">
function yulan2(str){
var obj = document.getElementById(str);
var str = getPath(obj);
document.getElementById('image').style.display="";
var liulanqi = getOs();
if(liulanqi=="Safari")
{document.getElementById('image2').innerHTML = "该款浏览器无法正常显示待上传的图片,但不会影响图片的正常上传,若要显示待上传的图片,推荐使用IE浏览器登录本系统!";}
else
{document.getElementById('image2').innerHTML = "<img src='" + str + "' />";}
}
function getOs()
{
var OsObject = "";
if(navigator.userAgent.indexOf("MSIE")>0) {
return "MSIE";
}
if(isFirefox=navigator.userAgent.indexOf("Firefox")>0){
return "Firefox";
}
if(isSafari=navigator.userAgent.indexOf("Safari")>0) {
return "Safari";
}
if(isCamino=navigator.userAgent.indexOf("Camino")>0){
return "Camino";
}
if(isMozilla=navigator.userAgent.indexOf("Gecko/")>0){
return "Gecko";
}
}

//获取以下即为完整客户端路径
function getPath(obj) {
if(obj){
if(window.navigator.userAgent.indexOf("MSIE") >= 1) {
obj.select(); return document.selection.createRange().text;
}else if(window.navigator.userAgent.indexOf("Firefox") >= 1) {
if (obj.files) {
return obj.files.item(0).getAsDataURL();
}
return obj.value;
}
return obj.value;
}
}
</script>
kuailelj 2011-10-12
  • 打赏
  • 举报
回复
<input type="file" name="link_pic" class="fl file_input" id="tupian" />
<input type="button" class="upload_btn fl" value="上传" onclick="yulan2('tupian');" />
<tr style="display:none" id="image">
<td width="100px">  图片预览</td>
<td><div id="image2"></div></td>
JS代码如下:<script>
function yulan2(str){
var obj = document.getElementById(str);
var str = getPath(obj);
document.getElementById('image').style.display="";
var liulanqi = getOs();
if(liulanqi=="Safari")
{document.getElementById('image2').innerHTML = "该款浏览器无法正常显示待上传的图片,但不会影响图片的正常上传,若要显示待上传的图片,推荐使用IE浏览器登录本系统!";}
else
{document.getElementById('image2').innerHTML = "<img src='" + str + "' />";}
}
function getOs()
{
var OsObject = "";
if(navigator.userAgent.indexOf("MSIE")>0) {
return "MSIE";
}
if(isFirefox=navigator.userAgent.indexOf("Firefox")>0){
return "Firefox";
}
if(isSafari=navigator.userAgent.indexOf("Safari")>0) {
return "Safari";
}
if(isCamino=navigator.userAgent.indexOf("Camino")>0){
return "Camino";
}
if(isMozilla=navigator.userAgent.indexOf("Gecko/")>0){
return "Gecko";
}
}

//获取以下即为完整客户端路径
function getPath(obj) {
if(obj){
if(window.navigator.userAgent.indexOf("MSIE") >= 1) {
obj.select(); return document.selection.createRange().text;
}else if(window.navigator.userAgent.indexOf("Firefox") >= 1) {
if (obj.files) {
return obj.files.item(0).getAsDataURL();
}
return obj.value;
}
return obj.value;
}
}

为什么Firefox可以预览。但是IE却显示X?求完整代码
xuzuning 2011-10-12
  • 打赏
  • 举报
回复
onmouseo教程ut
改为
onmouseout

这更说明:网上粘贴下来的代码并不是都能直接使用的
sink 2011-10-12
  • 打赏
  • 举报
回复
晕,你把教程2个字去掉
onmouseout=
kuailelj 2011-10-12
  • 打赏
  • 举报
回复
[Quote=引用 7 楼 zell419 的回复:]
引用 6 楼 kuailelj 的回复:

各位大侠,为什么这段代码代码总会使IE中预览不出图片呢?

你是IE几 ?
好像只有6能跑 。
其实 图片预览这个玩意 纯前台 没什么意义了 。
[/Quote]
IE8的,
zell419 2011-10-12
  • 打赏
  • 举报
回复
[Quote=引用 6 楼 kuailelj 的回复:]

各位大侠,为什么这段代码代码总会使IE中预览不出图片呢?
[/Quote]
你是IE几 ?
好像只有6能跑 。
其实 图片预览这个玩意 纯前台 没什么意义了 。
kuailelj 2011-10-12
  • 打赏
  • 举报
回复
各位大侠,为什么这段代码代码总会使IE中预览不出图片呢?

87,990

社区成员

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

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