zoukankan      html  css  js  c++  java
  • 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();
                    }
                }
            }
  • 相关阅读:
    C# Mongo Client 2.4.2创建索引
    MongoDB Driver:使用正确的姿势连接复制集
    C# Mongo Client 2.4.2判断是否存在表
    c# Mongodb批量更新
    c# Mongodb创建自增列
    class A where T:new()是什么意思
    Dapper Extensions中修改Dialect
    golang 中的 sizeof 以及 golang中的 union
    将c语言的结构体定义变成对应的golang语言的结构体定义,并将golang语言结构体变量的指针传递给c语言,cast C struct to Go struct
    golang 与 c语言 之间传递指针的规则提案
  • 原文地址:https://www.cnblogs.com/ding0910/p/340695.html
Copyright © 2011-2022 走看看