Jon*_*onH 2 javascript asp.net jquery
不幸的是我的前端技能缺乏,因为我的角色让我更多地使用服务器端/ db技术而不是css/js.无论如何,我试图实现这个:
更具体地说,我能够在这里找到一个asp.net示例:
基本上允许您进行大规模图像上传.我已经用正确的css和js文件设置了前端.我不得不修改一些js文件中作出的使用on(),而不是live()作为现场已被弃用.我的表单加载,如下所示:

到目前为止一切都很好,但是,只要我"添加文件"或拖放文件,Chrome开发人员工具就会告诉我以下内容:
Uncaught TypeError: Cannot read property '_adjustMaxNumberOfFiles' of undefined
它指定文件jquery.fileupload-ui.js,更具体地指向我:
var that = $(this).data('fileupload');
that._adjustMaxNumberOfFiles(-data.files.length);
Run Code Online (Sandbox Code Playgroud)
我alert编辑that,当然它似乎是未定义的...但我不知道足够的jquery来理解为什么它是未定义的.我的fileupload div标记如下:
<div id="fileupload">
<form action="/Handler.ashx" method="POST" enctype="multipart/form-data">
<div class="fileupload-buttonbar">
<label class="fileinput-button">
<span>Add files...</span>
<input id="file" type="file" name="files[]" multiple>
</label>
<button type="submit" class="start">Start upload</button>
<button type="reset" class="cancel">Cancel upload</button>
<button type="button" class="delete">Delete files</button>
</div>
</form>
<div class="fileupload-content">
<table class="files"></table>
<div class="fileupload-progressbar"></div>
</div>
</div>
Run Code Online (Sandbox Code Playgroud)
那么可能导致这种情况未定义的原因是什么?这是什么_adjustMaxNumberOfFiles呢
_adjustMaxNumberOfFiles: function (operand) {
if (typeof this.options.maxNumberOfFiles === 'number') {
this.options.maxNumberOfFiles += operand;
if (this.options.maxNumberOfFiles < 1) {
this._disableFileInputButton();
} else {
this._enableFileInputButton();
}
}
},
Run Code Online (Sandbox Code Playgroud)
我正在使用jquery 2.0.3和jquery ui 1.10.3
我已经说到我发布的示例链接(上面的第二个链接)唯一的区别是它们正在使用的jquery版本,似乎是1.8.2而我使用的是2.0.3.差异和问题是这段代码:
var that = $(this).data('fileupload');
在示例下载中,这将返回一些奇怪的对象:
a.(anonymous function).(anonymous function) {element: e.fn.e.init[1], options: Object, _sequence: Object, _total: 0, _loaded: 0…}
在我的版本中(使用2.0.3)我得到了未定义:
var that = $(this).data('fileupload');
还有另一种方法可以做这一行代码吗?
在控制台窗口中玩了很多次后,我得到了它:
var that = $("#fileupload").data('blueimpUI-fileupload');
所以对于任何使用任何东西> jQuery 1.8的人,请更改此行:
var that = $(this).data('fileupload');
对此:
var that = $("#fileupload").data('blueimpUI-fileupload');