一、querySelectorAll
document.querySelectorAll('h1')//获取页面所有h1元素
document.querySelectorAll('h1.text.modal-title')//获取页面元素为h1属性为text.modal-title的所有元素
document.querySelectorAll('h1.text.modal-title')[0]//获取页面元素为h1属性为text.modal-title的第一个元素它的html具体内容
本文介绍了querySelectorAll方法在JavaScript中如何用于选取HTML页面上具有特定属性的元素,如h1.text.modal-title,并展示了如何获取单个元素及其内容。
一、querySelectorAll
document.querySelectorAll('h1')//获取页面所有h1元素
document.querySelectorAll('h1.text.modal-title')//获取页面元素为h1属性为text.modal-title的所有元素
document.querySelectorAll('h1.text.modal-title')[0]//获取页面元素为h1属性为text.modal-title的第一个元素它的html具体内容
1641
428

被折叠的 条评论
为什么被折叠?