• sharepoint 2013 附件控件FileUpload怎样检验是否为图片的方法


    记录一下关于附件控件FileUpload怎样检验是否为图片的方法:

    function checkImg() {

           var fileObj =document.getElementById('<%=FileObj.ClientID%>');

           var str =fileObj.value;

           if (str !='') {

               if(str.substring((str.lastIndexOf(".jpg"))) == (".jpg")

                   ||str.substring((str.lastIndexOf(".gif"))) == (".gif")

                   ||str.substring((str.lastIndexOf(".png"))) == (".png")

                   ) {

               }

               else {

                   alert('仅仅同意jpg,gif,png图片格式!');

                   returnfalse;

               }

           }

        }

    function GetFileName(path) {

            var pos1 =path.lastIndexOf('/');

            var pos2 =path.lastIndexOf('\');

            var pos =Math.max(pos1, pos2)

            var ext =path.substring(path.lastIndexOf("."), path.length).toLowerCase();

            var TxtFileNameObj =document.getElementById('<%= txtFileName.ClientID %>');

            if (pos< 0) {

               TxtFileNameObj.value = path;

            }

            else {

               TxtFileNameObj.value = path.substring(pos + 1);

            }

            filename =TxtFileNameObj.value;

           TxtFileNameObj.value = filename.substring(0, filename.length -ext.length).toLowerCase();

            checkImg();

        }

     

     

    <asp:FileUploadID="FileObj"runat="server"Width="300"onchange="GetFileName(this.value);"/>

    <asp:TextBoxID="txtFileName"runat="server"Width="290" ></asp:TextBox>

     

    当中GetFileName(this.value)方法。是选择上传的附件之后。顺便获取文件的名称,而且赋值到txtFileName。

  • 相关阅读:
    BZOJ3868 : The only survival
    BZOJ3740 : pku2842 N-dimension Matching N维匹配
    BZOJ2990 : [Ontak2010]Keyboard
    BZOJ3548 : [ONTAK2010]Party
    BZOJ3189 : [Coci2011]Slika
    BZOJ2679 : [Usaco2012 Open]Balanced Cow Subsets
    BZOJ2981 : [Poi2002]括号
    BZOJ4116 : [Wf2015]Tours
    BZOJ4107 : [Wf2015]Asteroids
    BZOJ4118 : [Wf2015]Window Manager
  • 原文地址:https://www.cnblogs.com/yangykaifa/p/7133849.html
Copyright © 2020-2023  润新知