jQuery :file 選擇器


jQuery 中的 :file 選擇器用於選擇所有型別為“file”的 input 元素。

語法

語法如下 −

$(":file")

示例

現在我們看看一個實現 :file() 選擇器的示例 −

<!DOCTYPE html>
<html>
<head>
<style>
   .demo {
      background-color: blue;
      color: white;
      font-size: 16px;
      border: 2px blue dashed;
   }
</style>
<script src="https://code.jquery.com/jquery-3.4.1.js"></script>
<script>
   $(document).ready(function(){
      $(":file").addClass("demo");
   });
</script>
</head>
<body>
<h2>Job Application</h2>
<form action="">
Applicant Name: <input type="text" name="cname"><br>
Rank: <input type="number" name="rank"><br><br>
Resume: <input type="file" name="myfile">
</form>
</body>
</html>

輸出

這將產生以下輸出 −

更新於:05-11-2019

502 次瀏覽

啟動你的 職業生涯

透過完成課程來獲得認證

開始
廣告