
- jQuery 教程
- jQuery - 首頁
- jQuery - 路線圖
- jQuery - 概述
- jQuery - 基礎
- jQuery - 語法
- jQuery - 選擇器
- jQuery - 事件
- jQuery - 屬性
- jQuery - AJAX
- jQuery DOM 操作
- jQuery - DOM
- jQuery - 新增元素
- jQuery - 刪除元素
- jQuery - 替換元素
- jQuery CSS 操作
- jQuery - CSS 類
- jQuery - 尺寸
- jQuery - CSS 屬性
- jQuery 效果
- jQuery - 效果
- jQuery - 動畫
- jQuery - 鏈式呼叫
- jQuery - 回撥函式
- jQuery 遍歷
- jQuery - 遍歷
- jQuery - 遍歷祖先節點
- jQuery - 遍歷後代節點
- jQuery UI
- jQuery - 互動
- jQuery - 小部件
- jQuery - 主題
- jQuery 參考
- jQuery - 選擇器
- jQuery - 事件
- jQuery - 效果
- jQuery - HTML/CSS
- jQuery - 遍歷
- jQuery - 雜項
- jQuery - 屬性
- jQuery - 工具函式
- jQuery 外掛
- jQuery - 外掛
- jQuery - PagePiling.js
- jQuery - Flickerplate.js
- jQuery - Multiscroll.js
- jQuery - Slidebar.js
- jQuery - Rowgrid.js
- jQuery - Alertify.js
- jQuery - Progressbar.js
- jQuery - Slideshow.js
- jQuery - Drawsvg.js
- jQuery - Tagsort.js
- jQuery - LogosDistort.js
- jQuery - Filer.js
- jQuery - Whatsnearby.js
- jQuery - Checkout.js
- jQuery - Blockrain.js
- jQuery - Producttour.js
- jQuery - Megadropdown.js
- jQuery - Weather.js
- jQuery 有用資源
- jQuery - 常見問題解答
- jQuery - 快速指南
- jQuery - 有用資源
- jQuery - 討論
jQuery :radio 選擇器
jQuery 中的 :radio 選擇器用於選擇所有型別為 "radio" 的 input 元素。透過選擇,我們可以操作單選按鈕,例如“選中”、“停用”等。
語法
以下是 jQuery 中 :radio 選擇器的語法:
$(":radio")
引數
以下是上述語法的描述
- ":radio" − 此選擇器將選擇文件中所有單選按鈕元素。
示例 1
在下面的示例中,我們使用 ":radio" 選擇器來選擇所有型別為 "radio" 的 <input> 元素:
<html> <head> <script src="https://code.jquery.com/jquery-3.6.0.min.js"></script> <script> $(document).ready(function() { $('button').click(function() { $(':radio').wrap("<span style='background-color:yellow'>"); }); }); </script> </head> <body> <form> <input type="text" name="username" placeholder="Enter text here"><br> Male: <input type="radio"><br> Female: <input type="radio"><br> <button>Click</button> </form> </body> </html>
如果我們執行並點選按鈕,它會選擇所有型別為 radio 的 input 元素,並用一個帶有黃色背景顏色的 span 元素將其包裹起來。
示例 2
在這個例子中,我們停用了表單中的所有單選按鈕:
<html> <head> <script src="https://code.jquery.com/jquery-3.6.0.min.js"></script> <script> $(document).ready(function() { $("button").click(function() { $(":radio").prop("disabled", true); }); }); </script> </head> <body> <form> <label> <input type="radio" name="option" value="1"> Option 1 </label> <label> <input type="radio" name="option" value="2"> Option 2 </label> <label> <input type="radio" name="option" value="3"> Option 3 </label> <br> <button>Disable All Radios</button> </form> </body> </html>
點選“停用所有單選按鈕”後,它會選擇所有型別為 radio 的 input 元素並將其停用。
jquery_ref_selectors.htm
廣告