我有
$ ( #basicUploadFile ).live ( change , function () {
alert($ ( #basicUploadFile ).val());
});
我该怎么做?
我有
$ ( #basicUploadFile ).live ( change , function () {
alert($ ( #basicUploadFile ).val());
});
我该怎么做?
var files = $( #basicUploadFile ).prop("files")
files
将是一个文件列表对象。
var names = $.map(files, function(val) { return val.name; });
现在 names
是一组字符串( 文件名)
您仍然可以将文件作为 FileList
收藏访问,而无需过度使用 jQuery
。 我创建了一个快速的 href="http://jsfiddle.net/r64uV/1/" rel="noreferr" >jsFiddle , 演示如何使用 FileList
和 File
对象从输入中获取信息。 这里有一个片断 :
$( #basicUploadFile ).live( change , function ()
{
for (var i = 0; i < this.files.length; i++)
{
alert(this.files[i].name);
alert(this.files.item(i).name); // alternatively
}
});
我用这个在控制台显示所有文件名称 :
var input_file = $("#input_file");
input_file.on("change", function () {
var files = input_file.prop("files")
var names = $.map(files, function (val) { return val.name; });
$.each(names, function (i, name) {
console.log(name);
});
});
<input name="selectAttachment" id="selectAttachment" type="file" multiple="multiple">
<button class="btn btn-default" onclick="uploadAttachment()" type="submit">Upload</button>
function uploadAttachment() {
debugger;
var files = $( #selectAttachment ).prop( files );
var names = $.map(files, function (val) { return val.name; });
}
您可以扩展 < strong > File 对象 strong > (例如 File. prototype.toJSON
) 的原型,您也可以访问 的文件列表 :
<input id="myFile" type="file">
var file = document.getElementById( fileItem ).files[0];
有关此文档的更多信息,请查看 :
File.prototype.toJSON = function() {
return {
lastModified : this.lastModified,
lastModifiedDate : this.lastModifiedDate,
name : this.name,
size : this.size,
type : this.type
};
}
function getFiles() {
var files = document.getElementById( myFiles ).files;
document.getElementById( result ).innerHTML = <h1>result</h1>
+ JSON.stringify(files);
}
<input id="myFiles" type="file" multiple onchange="getFiles()" />
<pre id= result ></pre>
祝你好运!
How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.
I would like to click a link in my page using javascript. I would like to Fire event handlers on the link without navigating. How can this be done? This has to work both in firefox and Internet ...
Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...
Is there a reliable way to access the client machine s clipboard using Javascript? I continue to run into permissions issues when attempting to do this. How does Google Docs do this? Do they use ...
I have a large javascript which I didn t write but I need to use it and I m slowely going trough it trying to figure out what does it do and how, I m using alert to print out what it does but now I ...
Is it possible for someone to give me a few pointers on how to display a multidimensional array in the form of a bar graph? The array is multidimensional, with three elements in each part - and the ...
Is it possible to reload a form after file-input change? I have a form where the user can chose an image for upload. I also have a php script which displays that image resized. I only wonder if it ...
I ve made a little forum and I want parse the date on newest posts like twitter, you know "posted 40 minutes ago ","posted 1 hour ago"... What s the best way ? Thanx.