1 ; (function ($) {
 2         $.fn.UpLoadFileSSY = function (userOption) {
 3             var option = {
 4                 posturl: "",//上传路径
 5                 callblackfunction: function () { }//回调函数
 6             };
 7             var options = $.extend({}, option, userOption || {});
 8 
 9             var file = $(this);
10             file.change(function () {
11                 var iframe_form = "<iframe id='UpLoadFileSSYIframeForId' name='UpLoadFileSSYIframeForName' style='display:none;'></iframe><form id='UpLoadFileSSYFormForId' method='post' target='UpLoadFileSSYIframeForName' action='' enctype='multipart/form-data'></form>";
12                 $(document.body).append(iframe_form);
13 
14                 var fileParent = file.parent();
15 
16                 var form = $("#UpLoadFileSSYFormForId");
17                 var iframe = $("#UpLoadFileSSYIframeForId");
18 
19                 form.attr("action", options.posturl);
20                 form.append(file);
21                 form.submit();
22 
23                 iframe.load(function () {
24                     file.appendTo(fileParent);
25                     var result = iframe.contents().find('body').html().replace(/\<[^\>]*\>([^\<]*)\<[^\>]*\>/g, function ($0, $1) { return $1; });//todo  这里其实可以不用正则过滤的
26                     options.callblackfunction.call(this, eval(result));
27                     iframe.remove();
28                     form.remove();
29                 });
30             });
31         }
32     })(jQuery);

 

相关文章:

  • 2021-06-01
  • 2021-09-15
  • 2021-09-15
  • 2021-10-16
  • 2022-12-23
  • 2021-06-13
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-12-27
  • 2022-01-07
  • 2021-12-27
相关资源
相似解决方案