• JS判断是否为图片后缀名


    // 增加一个名为 IsPicture 的函数作为
        // String 构造函数的原型对象的一个方法。
        String.prototype.IsPicture = function()
        {
            
    //判断是否是图片 - strFilter必须是小写列举
            var strFilter=".jpeg|.gif|.jpg|.png|.bmp|.pic|"
            
    if(this.indexOf(".")>-1)
            {
                
    var p = this.lastIndexOf(".");
                
    //alert(p);
                //alert(this.length);
                var strPostfix=this.substring(p,this.length) + '|';        
                strPostfix = strPostfix.toLowerCase();
                
    //alert(strPostfix);
                if(strFilter.indexOf(strPostfix)>-1)
                {
                    
    //alert("True");
                    return true;
                }
            }        
            
    //alert('False');
            return false;            
        }

    //<!--前台HTML文件//-->//

    //预览图片
            function showImg()
            { 
                document.getElementById(
    "imgPic").removeAttribute("height");
                
    if(document.getElementById("spnPic").style.display!="none")document.getElementById("spnPic").style.display='none';
                
    if(document.getElementById("Image").value.trim()!='')
                {    
                    
    //IsPic();
                    document.getElementById("imgPic").style.display='';
                    document.getElementById(
    "imgPic").src=document.getElementById("Image").value.trim();    
                    
    if(document.getElementById("imgPic").height>150) document.getElementById("imgPic").height=150;
                    
    //if(document.getElementById("imgPic")>300) document.getElementById("imgPic").width=300;            
                }            
                
    else
                {
                    document.getElementById(
    "imgPic").style.display='none';
                    document.getElementById(
    "imgPic").src='';
                }        
            }
            
            
    //图片验证
            function IsPic()
            {
                
    if(document.getElementById("Image").value.trim()!='')
                {
                    
    if(document.getElementById("Image").value.IsPicture()==false)
                    {
                        alert('请选择正确的图片路径!');
                        document.getElementById(
    "Image").focus();
                        document.getElementById(
    "Image").select();
                    }
                }
            }
  • 相关阅读:
    笨笨走了
    WSE 3.0 文档翻译:WSE架构
    系列文章索引
    WSE 3.0 文档翻译:WSE的新功能
    人分四品
    手把手教你装饰vs2005项目上如何添加右键菜单
    递归算法学习系列之三(快速排序)
    ip地址与数字相互转换的sql函数
    递归算法学习系列之寻找第K大
    WSE 3.0 文档翻译:什么时候使用WSE 3.0
  • 原文地址:https://www.cnblogs.com/ding0910/p/340695.html
Copyright © 2020-2023  润新知