Jquery,获取输入类型=“文件”的值场地
如果以下代码有任何问题,有人可以告诉我吗?我正在尝试获取输入类型=“文件”表单标签的值,但警报一直告诉我它是空的
$('#submitForm').bind("click",function(){
var imgVal = $('#imageUpload').val();
alert(imgVal);
return false;
});
<input name="imageUpload" id="imageUpload" type="file" value="" class="text"/>
<input name="submit" type="submit" id="submitForm" value="Submit Photo" />
提前感谢
詹姆斯
Can anybody let me know if there is anything wrong with the following code. I'm trying to get the value of a input type="file" form tag but the alert keeps telling me it's empty
$('#submitForm').bind("click",function(){
var imgVal = $('#imageUpload').val();
alert(imgVal);
return false;
});
<input name="imageUpload" id="imageUpload" type="file" value="" class="text"/>
<input name="submit" type="submit" id="submitForm" value="Submit Photo" />
Thanks in advance
James
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
对我有用。
查看 jsFiddle 演示:
Works for me.
See working jsFiddle demo:
这应该适用于任何浏览器
This should work on any browser
你还可以这样做:
var imgVal = document.getElementById("imageUpload");
然后要获取该值,请执行以下操作:
alert(imgVal.value);
要记住的一件事是,许多浏览器都会为您提供该文件,但它会隐藏实际路径,如下所示:
C:/fakepath/filename.extension
You could also do:
var imgVal = document.getElementById("imageUpload");
Then to get the value do something like this:
alert(imgVal.value);
One thing to remember is that many browsers will give you the file, but it will hide the actual path with something like this:
C:/fakepath/filename.extension
当任何用户选择文件时,然后在 jquery 中检测文件元素值是否发生变化
将此代码放入 jQuery 文件中
当用户选择文件时,文件类型按钮启用,表单上传按钮禁用,那么它的值将更改并启用上传按钮,这意味着我们可以提交表单。
when any user select file then to detect in jquery is file element value change or not
put this code in jQuery file
file type button is enable and upload button of form is disable when user will select file then it's value will change and enable upload button which means then we can submit our form.
你可以使用
You can use