| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1172 人关注过本帖
标题:求助判断文件格式问题
只看楼主 加入收藏
thbwn
Rank: 1
等 级:新手上路
帖 子:235
专家分:0
注 册:2007-10-2
结帖率:80%
收藏
已结贴  问题点数:10 回复次数:4 
求助判断文件格式问题
现在的代码的效果是,选中文件,如果文件类型不正确,重新刷新该页.我想实现这样的效果,该怎么改?

input file 浏览选中文件,类型不正确,将该input file框自动清零,而其他input file不变.谢谢!

<html>
<head>
<title>文件传送</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<style type="text/css">
<!--
td {  font-size: 9pt}
a {  color: #000000; text-decoration: none}
a:hover {  text-decoration: underline}
.tx {  height: 16px; width: 30px; border-color: black black #000000; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 1px; border-left-width: 0px; font-size: 9pt; background-color: #eeeeee; color: #0000FF}
.bt {  font-size: 9pt; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; height: 16px; width: 80px; background-color: #eeeeee; cursor: hand}
.tx1 { height: 20px; width: 30px; font-size: 9pt; border: 1px solid; border-color: black black #000000; color: #0000FF}
.STYLE6 {color: #FF0000}
.STYLE8 {font-size: 12px}
-->
</style>
</head>
<body>

<script language="javascript">
function GetFilePath(obj)
  {
  //alert(obj);
  var physical = document.getElementById(obj).value;
  var length = physical.length;
  var charindex = physical.lastIndexOf(".");
  var ExtentName = physical.substr(charindex,5)
  var vExtentName = ExtentName.toLowerCase(ExtentName) //* 将扩展名转换成小写
  //*上传允许的文件类型
  if(!(vExtentName == ".txt" || vExtentName == ".ps" || vExtentName == ".rar" || vExtentName == ".zip" || vExtentName == ".doc" ))
  
  {
    alert("文件类型不正确:"+vExtentName+"");
    window.location.href = "index.htm";
   return false;
  }
  
  }

</script>

<form name="myform" method="post" action="Example_Progress.asp" enctype="multipart/form-data" target="upload">
 <table border="1" cellspacing="0" cellpadding="0" bordercolorlight="#000000" bordercolordark="#CCCCCC" width="91" height="23">
    <tr>
      <td align="left" valign="middle" height="18" width="18">&nbsp;</td>
      <td bgcolor="#FFCC00" align="left" valign="middle" height="18" width="67"> 节目表传送</td>
    </tr>
  </table>
  <br>
<table width="680" border="1" align="center" cellpadding="5" cellspacing="0" bordercolor="#000000" bordercolorlight="#000000" bordercolordark="#CCCCCC">
    <tr bgcolor="#CCCCCC">
      <td height="22" align="left" valign="middle" bgcolor="#FFFFCC">&nbsp;<strong>节目表传送专用通道(<span class="STYLE6">合作愉快,谢谢支持!</span>) </strong></td>
    </tr>
    <tr align="left" valign="middle" bgcolor="#eeeeee">
      <td bgcolor="#eeeeee" height="42">
        <script language="javascript">
      function setid()
      {
      str='<br>';
      if(!window.myform.upcount.value)
       window.myform.upcount.value=2;
       for(i=1;i<=window.myform.upcount.value;i++)
         str+='文件'+i+':<input id="file'+i+'" type="file" name="filefield'+i+'" style="width:400" class="tx1" value="" onchange=GetFilePath("file'+i+'")><br><br>';
      window.upid.innerHTML=str+'<br>';
      }
      </script>
        <li> 需要传送的文件个数
          <input type="text" name="upcount" class="tx" value="2">
          <input type="button" name="Button" class="bt" onClick="setid();" value="· 设定 ·">
        </li>
        <br>              </td>
    </tr>
    <tr align="center" valign="middle">
      <td align="left" id="upid" height="116">  <input id=File type="file" name="filefield1" value="" onchange=GetFilePath("File")>        </td>
    <tr align="center" valign="middle" bgcolor="#eeeeee"><td bgcolor="#eeeeee" height="24">
         <input type="button" value="· 提交 ·" class="bt" onClick="UploadData()">
        <input type="reset" name="Submit2" value="· 重执 ·" class="bt"></td>
    </tr>
  </table>
</form>
<br>
</body>
</html>
<script language="javascript">
setid();
</script>
搜索更多相关主题的帖子: 判断 文件 格式 
2010-02-10 21:50
aspic
Rank: 17Rank: 17Rank: 17Rank: 17Rank: 17
等 级:贵宾
威 望:51
帖 子:2258
专家分:8050
注 册:2008-2-18
收藏
得分:10 
如果你重定向 那别的不都被清空了吗
2010-02-11 08:37
aspic
Rank: 17Rank: 17Rank: 17Rank: 17Rank: 17
等 级:贵宾
威 望:51
帖 子:2258
专家分:8050
注 册:2008-2-18
收藏
得分:0 
好像可以直接覆盖原来的OuterHTML 但是IEonly
2010-02-11 09:17
aspic
Rank: 17Rank: 17Rank: 17Rank: 17Rank: 17
等 级:贵宾
威 望:51
帖 子:2258
专家分:8050
注 册:2008-2-18
收藏
得分:0 
http://zhidao.baidu.com/question/109869690
2010-02-11 09:21
thbwn
Rank: 1
等 级:新手上路
帖 子:235
专家分:0
注 册:2007-10-2
收藏
得分:0 
谢谢,我试试

          人人为我,我为人人!
2010-02-11 19:55
快速回复:求助判断文件格式问题
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.019784 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved