国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 語言 > JavaScript > 正文

jQuery函數的第二個參數獲取指定上下文中的DOM元素

2024-05-06 16:06:14
字體:
來源:轉載
供稿:網友
這篇文章主要介紹了jQuery函數的第二個參數獲取指定上下文中的DOM元素,需要的朋友可以參考下

jQuery函數的第二個參數可以指定DOM元素的搜索范圍。

第二個參數可分為以下類型

DOM reference
jQuery wrapper
document

代碼示例

復制代碼 代碼如下:


<!DOCTYPE html>
<html>
<body>
<form>
<input type="checkbox"/>
<input type="radio"/>
<input type="text"/>
<input type="button"/>
</form>
<form>
<input type="checkbox"/>
<input type="radio"/>
<input type="text"/>
<input type="button"/>
</form>
<input type="checkbox"/>
<input type="radio"/>
<input type="text"/>
<input type="button"/>

<script type="text/javascript" src="jquery-1.11.1.js"></script>
<script type="text/javascript">
// search within all form elements, using a wrapper for context,
// alerts "8 inputs"
alert("selected" + $('input', $('form')).length + ' inputs');

// search with the first form element, using DOM reference as the context,
// alerts "4 inputs"
alert("selected" + $('input', document.forms[0]).length + ' inputs');

// search within the body element for all input elements using an expression,
// alerts "12 inputs"
alert("selected" + $('input', 'body').length + ' inputs');
</script>
</body>
</html>


總結

第二個參數的不同的類型,對應的用法如下表所示。

類型用法

jQuery wrapper$('input', $('form')).length

DOM reference$('input', document.forms[0]).length

document$('input', 'body').length

發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表

圖片精選

主站蜘蛛池模板: 宁德市| 屏山县| 剑河县| 抚顺县| 精河县| 吉安县| 镇赉县| 鞍山市| 龙海市| 疏附县| 木兰县| 漳平市| 军事| 广西| 武功县| 邢台县| 卢龙县| 航空| 大荔县| 江阴市| 三台县| 榆树市| 方城县| 湟源县| 宁都县| 漳州市| 集贤县| 柳河县| 建昌县| 长垣县| 江陵县| 屯门区| 天水市| 和平区| 商洛市| 泽州县| 岱山县| 弋阳县| 屏山县| 齐河县| 黄冈市|