【发布时间】:2012-05-21 10:03:00
【问题描述】:
在 Google Chrome 浏览器中,我尝试了几种方法 + 以下方法,但没有一种方法给我附加的文件名的值,验证后我将提交文件。但总是找不到它的未定义或 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;
【问题讨论】:
-
Uncaught TypeError: Object #<HttmlinputElement> has no mehtod 'val'这就是它在尝试使用$(v).val()时返回的结果。 -
认真的吗?
$(v)返回一个 jquery 对象 -
旁注:
id应该是唯一的。例如使用attachment1、attachment2、...、attachmentn。
标签: javascript jquery internet-explorer firefox google-chrome