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);