jq或者js通过div的id获取里面所有p标签class为title的内容
<divid="test"><pclass="title">1111</p><pclass="content">10101010</p><pclass="title">2...
<div id="test">
<p class="title">1111</p>
<p class="content">10101010</p>
<p class="title">222</p>
<p class="content">20202020</p>
<p class="title">333</p>
<p class="content">30303030</p>
</div> 展开
<p class="title">1111</p>
<p class="content">10101010</p>
<p class="title">222</p>
<p class="content">20202020</p>
<p class="title">333</p>
<p class="content">30303030</p>
</div> 展开
1个回答
展开全部
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>获取内容</title>
</head>
<body>
<div id="test">
<p class="title">1111</p>
<p class="content">10101010</p>
<p class="title">222</p>
<p class="content">20202020</p>
<p class="title">333</p>
<p class="content">30303030</p>
</div>
<script src="https://cdn.bootcss.com/jquery/1.12.4/jquery.min.js"></script>
<script>
var array = $('#test').find('p.title').map(function (index, ele) {
return ele.innerHTML;
}).get();
console.log(array);
</script>
</body>
</html>
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询