相关疑难解决方法(0)

JQuery - 获取input ='file'中的所有文件名

我有<input type="file" id="basicUploadFile" multiple="multiple">,我想在这个输入中获取所有文件名.我见过一些例子,但它只获得了第一个文件的名称.

$ ('#basicUploadFile').live ('change', function () {
    alert($ ('#basicUploadFile').val());
});
Run Code Online (Sandbox Code Playgroud)

我怎样才能做到这一点?谢谢.

javascript jquery

33
推荐指数
2
解决办法
7万
查看次数

如何使用JavaScript或JQuery从input type = file html元素获取文件名?

在谷歌C​​hrome浏览器中,我尝试了几种方式+跟随,没有人给我附加的文件名的值,验证后我将提交文件.但总是找不到undefined或val().

怎么解决?

console.log($("input[name='attachment[]']"));
/* Output:
[
<input type=?"file" name=?"attachment[]?" id=?"attachment">?
, 
<input type=?"file" name=?"attachment[]?" id=?"attachment">?
, 
<input type=?"file" name=?"attachment[]?" id=?"attachment">?
]
*/

$.each($("input[name='attachment[]']"), function(i,v) {
    console.log(i);
    console.log(v); //v.val() does not exist... even uploaded a file and showing file

});

/* Output: 
0
<input type=?"file" name=?"attachment[]?" id=?"attachment">?
1
<input type=?"file" name=?"attachment[]?" id=?"attachment">?
2
<input type=?"file" name=?"attachment[]?" id=?"attachment">?
*/

return false;
Run Code Online (Sandbox Code Playgroud)

javascript firefox jquery internet-explorer google-chrome

17
推荐指数
3
解决办法
7万
查看次数

如何在IE9中访问Event.target?

HTML DOM对象模型定义具有属性Event对象.target

查看MSDN,Microsoft记录了一个target属性.它们还记录srcElementtarget早期版本的Internet Explorer 的别名:

目标性质类似于srcElement在Windows Internet Explorer 8和更早版本.


所以我在Internet Explorer中,坐在click断点处:

<div class="day" onclick="divClick(this)">

function divClick(sender)
{
   var divCell = sender;
Run Code Online (Sandbox Code Playgroud)

F12工具控制台,我可以要求全局event对象:

>> event 
{
    actionURL : "",
    altKey : false,
    altLeft : false,
    behaviorCookie : 0,
    behaviorPart : 0,
    bookmarks : null,
    boundElements : {...},
    button : 0,
    buttonID : 0,
    cancelBubble : false
    ...
} …
Run Code Online (Sandbox Code Playgroud)

html events internet-explorer dom internet-explorer-9

11
推荐指数
2
解决办法
2万
查看次数

JavaScript/HTML5/jQuery拖放上传 - "未捕获的TypeError:无法读取未定义的属性'文件'"

在我有限制的JavaScript经验之前,我会告诉你.


目前,我有JavaScript代码:

$('#xhr-filebox').bind({
    "dragover": HandleDragEvent,
    "dragleave": HandleDragEvent,
    "drop": HandleDropEvent
});

function HandleDropEvent(e){
    var files = e.target.files || e.dataTransfer.files;
    UploadFile(files[0]);
}
Run Code Online (Sandbox Code Playgroud)

(省略了一些代码,但如果你要求,我会添加更多代码)

......和HTML:

<div class="filebox" id="xhr-filebox">
    <p id="xhr-action">...or click me to pick one.</p>
</div>
Run Code Online (Sandbox Code Playgroud)

但是,当我将文件拖入其中时,Chrome JS控制台会说:

未捕获的TypeError:无法读取未定义的属性"文件"

但是,从文件输入读取时,它可以获取FileList对象.

奇怪的是,当我登录事件参数(执行console.log(E)),它会记录它作为f.event,而在我的一个类似的脚本,它会记录它的MouseEvent(截图:HTTP://i.stack.imgur .com/3krcT.png)

与jQuery中的bind()函数不同,它使用getElementById()返回的DOM对象的addEventListener()函数,IE这是纯JavaScript.我尝试过这种方法但没有新的事情发生.

javascript jquery html5 drag-and-drop file-upload

9
推荐指数
1
解决办法
1万
查看次数