zoukankan      html  css  js  c++  java
  • JS上传

    //异步上传文件,成功时,执行SuccessDo并返回1;
    //当失败时,返回JSON数据
    // url:文件要上传的url
    // fileId:要上传的文件名
    // 当上传文件成功时,执行ScuccessDo Function
    ///
    Ajax.FileUpload = function (url, fileId, SuccessDo) {
        var imageLoad;
        var imageLoadParent;
        var myform = document.createElement("form");
        myform.style.display = "none";
        myform.action = url;
        myform.enctype = "multipart/form-data";
        myform.method = "post";
    
        var is_chrome = /chrome/.test(navigator.userAgent.toLowerCase());
        if (is_chrome && document.getElementById(fileId).value == '')
            return; //Chrome bug onchange cancel
        if (document.all || is_chrome) {// IE 
            imageLoad = document.getElementById(fileId);
            imageLoadParent = document.getElementById(fileId).parentNode;
            myform.appendChild(imageLoad);
            document.body.appendChild(myform);
        }
        else { //FF
            imageLoad = document.getElementById(fileId).cloneNode(true);
            myform.appendChild(imageLoad);
            document.body.appendChild(myform);
        }
        $(myform).ajaxSubmit({
            success: function (responseText) {
                //这里请对应修改上传文件返回值,不要轻易把我删掉
                var res = responseText.split('|');
                alert(res[1]);
                if (res[0] == 1) {
                    $(".k-close").click();
                    $(".k-window,.k-overlay").remove();
                    SuccessDo();
                }
            }
        });
    }
  • 相关阅读:
    11.7表单事件 定时器
    11.5真11.6 函数调用 数组字符串的定义和方法
    11.2 面向对象 解析
    11.1 js数据类型 作用域 原型链
    10.31js中级作用域链和this
    定时器
    生出对象的方式
    学习this
    字符串
    全局方法
  • 原文地址:https://www.cnblogs.com/futao/p/2615205.html
Copyright © 2011-2022 走看看