gpt4 book ai didi

javascript - 在 div 中选择图像

转载 作者:行者123 更新时间:2023-11-28 03:20:01 25 4
gpt4 key购买 nike

<div>
<div id ="container">
<div>
<img src="some src>
</div>
<p>get this text</p>
<h>hello</h>
</div>
</div>

我想要主 div 中的图像总数,并且想要提取图像标签以外的 html 标签。
输出:
否。图片数量 =1
strings= <p>get this text</p><h>hello</h>

请给我一个演示

最佳答案

$("#container img").length - 对于 img标签数

为每个提取字符串,

$("#container").find("p, h").not("div").each(function() {
console.log($(this).get(0)); //Object
});

注意:您正在使用一些奇怪的 <h> 元素是一个无效的 HTML 标签,我认为它是 <h1>或其他一些标题元素。

关于javascript - 在 div 中选择图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24968328/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com