源码网商城,靠谱的源码在线交易网站 我的订单 购物车 帮助

源码网商城

jQuery函数的第二个参数获取指定上下文中的DOM元素

  • 时间:2021-07-19 20:16 编辑: 来源: 阅读:
  • 扫一扫,手机访问
摘要:jQuery函数的第二个参数获取指定上下文中的DOM元素
jQuery函数的第二个参数可以指定DOM元素的搜索范围。 第二个参数可分为以下类型 DOM reference jQuery wrapper document 代码示例
[u]复制代码[/u] 代码如下:
<!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 [code]$('input', $('form')).length[/code]
DOM reference [code]$('input', document.forms[0]).length[/code]
document [code]$('input', 'body').length[/code]
  • 全部评论(0)
联系客服
客服电话:
400-000-3129
微信版

扫一扫进微信版
返回顶部