jQuery :image 選擇器


jQuery 中的 :image 選擇器用於選擇所有 type=”image” 的 input 元素。

語法

語法如下 −

$(":image")

示例

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

<!DOCTYPE html>
<html>
<head>
<style>
   .demo {
      background-color: gray;
      border: 2px yellow dashed;
   }
</style>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<script>
   $(document).ready(function(){
      $(":image").addClass("demo");
   });
</script>
</head>
<body>
<h2>Login</h2>
<form action="">
Student Name: <input type="text" name="sname"><br>
Student ID: <input type="text" name="sid"><br><br>
Learn MySQL: <input type="image" src="https://tutorialspoint.tw/images/MySQL.png" width="31" height="30">
</form>
</body>
</html>

輸出

這將生成以下輸出 −

更新於:2019-11-05

259 瀏覽

開啟你的 職業生涯

完成教程以獲得認證

開始
廣告
© . All rights reserved.