
- 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 :only-of-type 选择器
jQuery 中的:only-of-type 选择器用于选择在其父元素内是其类型中唯一子元素的元素。
语法
以下是 jQuery :only-of-type 选择器的语法:
$(":only-of-type")
参数
此选择器目标是其类型在其父元素内唯一子元素的元素。
示例
在下面的示例中,我们使用 jQuery :only-of-type 选择器来选择每个<p>元素,该元素是其父元素(<div>)中唯一的<p>元素:
<html> <head> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script> <script> $(document).ready(function(){ $("p:only-of-type").css("background-color", "yellow"); }); </script> </head> <body> <div style="border: 1px solid black;"> <p>This paragraph is the only one of its type within the parent div.</p> <p>This paragraph is another paragraph within the parent div.</p> </div><br> <div style="border: 1px solid black;"> <p>This paragraph is the only one of its type within the parent div.</p> </div><br> <div style="border: 1px solid black;"> <p>This paragraph is the only one of its type within the parent div.</p> </div> </body> </html>
执行上述程序后,它会将其类型在 div 内唯一的段落应用黄色背景颜色。
jquery_ref_selectors.htm
广告