📌  相关文章
📜  如何使用jQuery在没有路径的情况下通过选定的文件名获取文件输入?

📅  最后修改于: 2021-10-31 05:37:46             🧑  作者: Mango

任务是使用 jQuery 通过选定的文件名获取文件输入,而不使用路径。要选择文件,我们将使用HTML 。之后,我们将使用 jQuery change() 方法获取文件名。 JQuery 中使用此方法来获取按选定文件名输入的文件。并且HTML 用于指定文件选择字段并添加一个按钮来选择要上传到表单的文件。
句法:

  • jQuery change() 方法:
$(selector).change(function)
  • HTML <输入类型=“文件”>:
 

以下示例说明了该方法:
示例 1:在本示例中,我们将使用 change() 方法显示带有扩展名的文件名,并且该文件将由 HTML 选择。

html


 

    
        How to get the file input by selected file
        name without the path using jQuery?
    
 
    
    

 

    

        GeeksforGeeks     

      

        How to get the file input by selected
        file name without the path using jQuery?     

           

            


html


 

    
        How to get the file input by selected file
        name without the path using jQuery?
    
 
    
    

 

    

        GeeksforGeeks     

      

        How to get the file input by selected
        file name without the path using jQuery?     

           

            


输出:

示例 2:在此示例中,我们将通过使用 change() 方法通过警报显示带有扩展名的文件名,并且该文件将由 HTML 选择。

html



 

    
        How to get the file input by selected file
        name without the path using jQuery?
    
 
    
    

 

    

        GeeksforGeeks     

      

        How to get the file input by selected
        file name without the path using jQuery?     

           

                

输出:

jQuery 是一个开源 JavaScript 库,它简化了 HTML/CSS 文档之间的交互,它以其“少写,多做”的理念而广为人知。
您可以按照此 jQuery 教程和 jQuery 示例从头开始学习 jQuery。