selectfilecontrol.js /** 这是一个专门用来进行文件选择的控件**//// (function ($, window) { function selectfile(dom, setting) { this.setting = $.extend(true, {}, selectfile.setting, setting); this.dom = $(dom); this.selectfil
/* * 这是一个专门用来进行文件选择的控件* */ /// (function ($, window) { function selectfile(dom, setting) { this.setting = $.extend(true, {}, selectfile.setting, setting); this.dom = $(dom); this.selectfiles = null; } selectfile.prototype.initstruct = function () { this.listeninputfile = this.dom.find('input[type="file"]'); this.filenameshowblock = this.dom.find(".filename"); } selectfile.prototype.bindevent = function () { var _self = this; this.listeninputfile.change(function () { _self.selectfiles = this.files; var names = ""; for (var i = 0; i < this.files.length; i++) { names += this.files[i].name + ";"; } names = names.substr(0, names.length - 1); if (_self.filenameshowblock.is("input")) { _self.filenameshowblock.val(names); } else { _self.filenameshowblock.html(names); } }) } selectfile.setting = { } $.fn.selectfile = function (parameters) { var $allModules = $(this); var query = arguments[0]; var methodInvoked = (typeof query == 'string'); var queryArguments = [].slice.call(arguments, 1); var returnedValue; $allModules.each(function () { if (methodInvoked) { var sf = $(this).data("selectfile"); if (sf) { returnedValue = sf[query].apply(sf, queryArguments); } } else { var sf = $(this).data("selectfile"); if (sf) { sf.destory(); } $(this).data("selectfile", new selectfile(this, parameters)); } }); return (returnedValue !== undefined) ? returnedValue : this; } }(jQuery, window))