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

首頁 > 編程 > JavaScript > 正文

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

2019-11-20 15:18:35
字體:
來源:轉載
供稿:網友
jQuery函數的第二個參數可以指定DOM元素的搜索范圍。

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

DOM reference
jQuery wrapper
document

代碼示例
復制代碼 代碼如下:

<!DOCTYPE html>
<html>
<body>
<form>
<input name="" type="checkbox"/>
<input name="" type="radio"/>
<input name="" type="text"/>
<input name="" type="button"/>
</form>
<form>
<input name="" type="checkbox"/>
<input name="" type="radio"/>
<input name="" type="text"/>
<input name="" type="button"/>
</form>
<input name="" type="checkbox"/>
<input name="" type="radio"/>
<input name="" type="text"/>
<input name="" 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
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 电白县| 崇左市| 温宿县| 华安县| 寿光市| 苗栗市| 柞水县| 忻州市| 元氏县| 山阴县| 桦甸市| 同江市| 铜山县| 清徐县| 白河县| 泉州市| 五寨县| 潜山县| 门头沟区| 黄龙县| 灵丘县| 建阳市| 萍乡市| 光泽县| 休宁县| 南川市| 宣恩县| 潼南县| 登封市| 鹿邑县| 林州市| 西丰县| 克拉玛依市| 中阳县| 苏尼特左旗| 北川| 新龙县| 潼关县| 关岭| 大理市| 株洲市|