我正在尝试从 href 链接调用上传文件功能,即使正在显示浏览框,我也无法对所选文件运行验证。这是我拥有的代码:
<a href="#" onclick="$('input[id=formmedia]').click();"><div class="sidebarSectionLink">Click here to add files</div></a> //Calls the browse box
<input type="file" id="formmedia" style="display: none;"> //Hidden input
//Post Photo Jquery
$('#formmedia').blur(function()
{
var pic=$("#formmedia").val();
if(pic.length < 1){
$('.sidebarSectionLink').html("Please Add A Photo").removeClass("success").addClass("error");
picok = 2;
}
else if(pic.indexOf('jpg') === -1 && pic.indexOf('jpeg') === -1 && pic.indexOf('png') === -1 && pic.indexOf('gif') === -1){
$('.sidebarSectionLink').html("Invalid File Format").removeClass("success").addClass("error");
picok = 2;
}
else {
picok = 1;
}
});