HIR*_*KUR 17 javascript jquery
我在href点击时触发文件上传.
我试图阻止除doc,docx和pdf之外的所有扩展.
我没有得到正确的警报值.
<div class="cv"> Would you like to attach you CV? <a href="" id="resume_link">Click here</a></div>
<input type="file" id="resume" style="visibility: hidden">
Run Code Online (Sandbox Code Playgroud)
使用Javascript:
var myfile="";
$('#resume_link').click(function() {
$('#resume').trigger('click');
myfile=$('#resume').val();
var ext = myfile.split('.').pop();
//var extension = myfile.substr( (myfile.lastIndexOf('.') +1) );
if(ext=="pdf" || ext=="docx" || ext=="doc"){
alert(ext);
}
else{
alert(ext);
}
})
Run Code Online (Sandbox Code Playgroud)
MyFiddle ..显示错误
Pet*_*der 56
您可以使用
<input name="Upload Saved Replay" type="file"
accept="application/pdf,application/msword,
application/vnd.openxmlformats-officedocument.wordprocessingml.document"/>
Run Code Online (Sandbox Code Playgroud)
whearat
application/pdf 手段 .pdfapplication/msword 手段 .docapplication/vnd.openxmlformats-officedocument.wordprocessingml.document 手段 .docx代替.
[编辑]警告,.dot也可能匹配.
ant*_*rat 14
最好change在输入字段上使用事件.
更新来源:
var myfile="";
$('#resume_link').click(function( e ) {
e.preventDefault();
$('#resume').trigger('click');
});
$('#resume').on( 'change', function() {
myfile= $( this ).val();
var ext = myfile.split('.').pop();
if(ext=="pdf" || ext=="docx" || ext=="doc"){
alert(ext);
} else{
alert(ext);
}
});
Run Code Online (Sandbox Code Playgroud)
更新了jsFiddle.
小智 6
仅对于资源管理器窗口中带有扩展名 doc 和 docx 的 acept 文件,请尝试此操作
<input type="file" id="docpicker"
accept=".doc,.docx,application/msword,application/vnd.openxmlformats-officedocument.wordprocessingml.document">
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
99227 次 |
| 最近记录: |