javascript - ajaxfileupload图片插件,点击选择文件按钮自动提交表单,求帮忙!
大家讲道理
大家讲道理 2017-04-11 11:52:52
[JavaScript讨论组]

问题:点击选择文件按钮,自动提交表单
代码:

//html


//js
$(document).delegate(".skuImage","change",function(){
    var stock_price_attr = $(this).attr('data_attr');
    if(stock_price_attr == 'skuImage'){
        var _this = $(this);
        var url = _this.val();
        if (window.createObjectURL != undefined) { // basic
            url = window.createObjectURL(_this.get(0).files[0]);
        } else if (window.URL != undefined) { // mozilla(firefox)
            url = window.URL.createObjectURL(_this.get(0).files[0]);
        } else if (window.webkitURL != undefined) { // webkit or chrome
            url = window.webkitURL.createObjectURL(_this.get(0).files[0]);
        }
        _this.siblings(".uploadPreview_img").find("img").attr("src", url);
        _this.siblings(".uploadPreview_img").show();
        _this.siblings(".uploadPreview_note").hide();
        $.ajaxFileUpload({
              var skuId = $(this).attr('dataid');
              url: 'upImage.do',//处理上传用的后台程序,可以是PHP,也可以是ASP等
              secureuri: false,//异步
              fileElementId: skuId,//上传skuId
              dataType: 'json',
              success: function(result) {
               if(result == '0' || result == ''){
                alert("上传失败,请重新上传!");
               }
              },
              error: function(result) {
                alert("上传失败,请重新上传!");
              }
        });
    }
});

//上传图片插件

jQuery.extend({


    createUploadIframe: function(id, uri)
    {
        //create frame
        var frameId = 'jUploadFrame' + id;

        if(window.ActiveXObject && !jQuery.support.opacity) {
            var io = document.createElement('