如何使用jQuery获取文件输入字段的当前值 [英] How to use jQuery to get the current value of a file input field

查看:80
本文介绍了如何使用jQuery获取文件输入字段的当前值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

从我准备好的时候,你应该可以使用文件输入字段的'value'属性来获取该字段的当前设置的路径。但是当我这样做:

From what I've ready you should be able to use the 'value' property of a file input field to get the currently set path of that field. But when I do this:

 $('#fileinput').value()

我得到'undefined'。我确定该字段的ID设置为fileinput。有没有人有什么想法为什么这可能不适用于我?

I get 'undefined'. The ID of the field is set to "fileinput" I'm sure. Does anyone have any thoughts on why this might not be working for me?

顺便说一句,这是有用的:

And by the way, this works:

var d = document.getElementById('AttachmentFile');
alert(d.value);

所以我想这与jQuery的工作方式有关,我不完全明白。

So I guess this has something to do with the way jQuery works that I don't fully understand.

谢谢!

推荐答案

你需要使用val而不是value 。

You need to use val rather than value.

$("#fileinput").val();

这篇关于如何使用jQuery获取文件输入字段的当前值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆