zoukankan      html  css  js  c++  java
  • 如何限制上传附件的格式?

    解决思路:1、在$(document).ready(function(){});中加上  $("#uploadFile").live("change",function () {};如下红色标记部分

    <script type="text/javascript">
            $(document).ready(function() {
                //$("#name").focus();
                var id=$("#id").val();
                if(id!=""){
                    $("#policeNo").attr("readonly","readonly")//
                }    
                $("#inputForm").validate({
                    submitHandler: function(form){
                        loading('正在提交,请稍等...');
                        form.submit();
                    },
                    errorContainer: "#messageBox",
                    errorPlacement: function(error, element) {
                        $("#messageBox").text("输入有误,请先更正。");
                        if (element.is(":checkbox")||element.is(":radio")||element.parent().is(".input-append")){
                            error.appendTo(element.parent().parent());
                        } else {
                            error.insertAfter(element);
                        }
                    }
                });            
                  $("#uploadFile").live("change",function () {
                        var filepath = $("input[name='uploadFile']").val();
                        var extStart = filepath.lastIndexOf(".");
                        var ext = filepath.substring(extStart, filepath.length).toUpperCase()
                        /* if(ext == "" or ext == null){
                            art.dialog.alert("请上传签字图片!");
                            return false;
                        } */
                        if( ext != "" && ext != ".BMP" && ext != ".PNG" && ext != ".GIF" && ext != ".JPG" && ext != ".JPEG") {
                            art.dialog.alert("图片限于bmp,png,gif,jpeg,jpg格式,且大小不能超过10M");
                            $("#uploadFile").remove();
                            $("#pic_add").append("<input id='uploadFile' type='file' name='uploadFile'
     accept=".png,.jpg,.gif,.jpeg,.ico,.bmp"/>");
                            return false;
                        } 
                  });      
            });
        </script>

    2、页面加载完成后开始运行do stuff when DOM is ready 中的语句!

       $(document).ready(function() {

               // do stuff when DOM is ready

            });

    3、$("a").click(function(){});的用法

    $("a").click(function() {

            alert("Hello world!");

             });

           });

    $("div").click $("div")就是页面中所有的 div标签 这句话就是给所有的标签为div的元素 绑定了一个click事件 即当所有div 被鼠标单击的时候 执行 alert("Hello World!");

    live方法绑定的事件处理函数,在页面中未来添加的元素只要满足原来的选择器,仍然会导致事件触发。

  • 相关阅读:
    前端常见跨域解决方案
    VS单元测试--初级篇
    高等数学思路
    二元函数求极值判别式AC-B^2
    向量积详解
    伯努利分布均值和方差
    两个标准正态随机变量相乘的方差
    a分位数与双侧a分位数
    中心极限定理概念理解与记忆
    样本方差概念解析
  • 原文地址:https://www.cnblogs.com/banxian-yi/p/5357480.html
Copyright © 2011-2022 走看看