我试图找到用户是否上传了任何图片..
以下是代码
<input type="file" name="profile_gallery[]">
<div id='submiform'>submit</div>
我先尝试了两种方法
$(function(){
$('#submitform').on('click', function(){
alert($('input[name=profile_gallery]').val());
});
});
,错误是
alert($('input[name=profile_gallery]').val()); //show undefined after and before selecting the file
第二个
$(function(){
$('#submitform').on('click', function(){
var profile_gallery = ($('input[name=profile_gallery]'))[0].files;
alert(profile_gallery.length);
});
});
,错误是
alert(profile_gallery.length); //Uncaught TypeError: Cannot read property 'files' of undefined