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

  • 相关阅读:
    .net core 反编译一小段
    .net core 自动注入。。。。懵逼。。
    css 过渡效果
    sqlserver 插入语句
    sqlserver 删除表 外键
    关于selenium的CI、框架……
    浅析selenium的PageFactory模式
    java使用IO读写文件总结
    selenium结合sikuliX操作Flash网页
    记阿里巴巴的一次面试
  • 原文地址:https://www.cnblogs.com/GISerp/p/2802238.html
Copyright © 2020-2023  润新知