zoukankan      html  css  js  c++  java
  • FileUpload控件客户端验证

    以下是示例

    <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title></title>
        <script type="text/javascript" language="javascript">
         
           function CheckFileType()
            {
                var objButton = document.getElementById("savebtn"); //上传按钮
                var objFileUpload=document.getElementById('FileUpload1');//FileUpload
               var objMSG=document.getElementById('msg');//显示提示信息用的DIV
                var FileName=new String(objFileUpload.value);//文件名
                var extension=new String (FileName.substring(FileName.lastIndexOf(".")+1,FileName.length));//文件扩展名
               
                if(extension=="jpg"||extension=="JPG")//你可以添加扩展名
                {
                     objButton.disabled=false;//启用上传按钮
                     objMSG.innerHTML="";
                }
                else
                {
                      objButton.disabled=true;//禁用上传按钮
                      objMSG.innerHTML="请选择正确的文件文件";
                 }
          }
           
       
        </script>

        <style type="text/css">
            .style1
            {
                103px;
            }
            #Text1
            {
                277px;
            }
        </style>
    </head>
    <body>
        <form id="form1" runat="server">
        <div>
            <table style=" 100%; ">
                <tr>
                    <td class="style1">
                        <label id="title" >标题</label>
                    </td
                    <td>
                        <input id="Text1" runat="server" type="text" />
                        <asp:Button ID="savebtn0" runat="server" Text="修改" onclick="savebtn_Click" />
                    </td>
                </tr>
                <tr>
                        <td class="style1">
                        <label id="Label1" >修改图片路径</label>
                    </td>
                    <td>
                         <input id="Radio1" type="radio" >使用默认路径</>
                    </td>
                    <td>
                        &nbsp;
                    </td>
                </tr>
                 <tr >
                    <td class= "style1">
                       
                    </td>
                    <td><input id="Radio2" type="radio" >上传图片</>
                        <asp:FileUpload ID="FileUpload1" runat="server" onChange="javascript:CheckFileType();" />
                    </td>
                    <td>
                     <div id="msg"></div>
                        <asp:Button ID="savebtn" runat="server" Text="保存" onclick="savebtn_Click" />
                    </td>
                </tr>
            </table>
        </div>
        </form>
    </body>
    </html>

  • 相关阅读:
    如何理解c和c++ 的复杂类型声明
    xp自带扫雷bug
    求三角形的外接圆
    判断一个点是否在一个三角形内
    三角函数角度公式
    弗洛伊德(Floyd)算法
    在Win32应用程序中用Console控制台输出信息
    无法打开libcp.lib
    C#获取当前应用程序所在路径及环境变量
    C#事件的发送方和接收方(订阅方)【转】
  • 原文地址:https://www.cnblogs.com/GISerp/p/2802238.html
Copyright © 2011-2022 走看看