首页 > 代码库 > sharepoint 2013 附件控件FileUpload怎样检验是否为图片的方法

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 = http://www.mamicode.com/path;

       }

       else {

           TxtFileNameObj.value = http://www.mamicode.com/path.substring(pos + 1);

       }

       filename =TxtFileNameObj.value;

       TxtFileNameObj.value = http://www.mamicode.com/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。

 

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