2013-10-23 25 views
0

我試圖運行一個函數,如果文件輸入類型是pdf。jQuery,如果文件輸入擴展名是.pdf,那麼運行功能

有沒有人知道一種方式,我可以在手之前用jQuery驗證文件擴展名?感謝

$('.uploadCV').click(function() { 

    if ($('.html-btn').val() === '.pdf') { 

     $('.join-us').flip({ 
      direction: 'rl', 
      color: '#38404b', 
      speed: 200, 
      onAnimation: function() { 
       $('.icon').fadeOut(); 
       $(this).css('margin-top', '20px'); 
      }, 
      content: '<span class="title">Uploading...</span><span class="summary">Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.</p>' 
     }) 
    } else { 
     console.log('dont upload'); 
    } 
}); 
+0

看看這裏:HTTP:// stackoverflow.com/questions/1606842/how-可以-I-GET-A-使用的文件上傳大小 - - 簡單的JavaScript/1606861#1606861 – sailingthoms

回答

1

如果字符串.pdf

Live Demo

fileName = $('.html-btn').val().toLowerCase(); 
if(fileName.indexOf('.pdf') == fileName.length - 4) { 
2

fiddle DEMO

您可以查看文件的擴展名.pdf

結束後,您可以檢查210個
var val = $('.html-btn').val(); 
var file_type = val.substr(val.lastIndexOf('.')).toLowerCase(); 
if (file_type === '.pdf') { 

參考

.substr()

.toLowerCase()

.lastIndexOf