gpt4 book ai didi

javascript - 使用基于 HR 标签的 Javascript/JQuery 在 div 中拆分 HTML

转载 作者:搜寻专家 更新时间:2023-10-31 22:33:55 25 4
gpt4 key购买 nike

我想根据 HR 标签将我从不同 DIV 中的网络服务收到的文章(= HTML 内容)拆分。

我用一个例子来解释,这是我从服务中收到的:

<p>This is an article bla bla</p> <hr/> <p>this is the next page of the article blabla ...</p>

我想根据 HR 标签制作:

<div><p>This is an article bla bla</p></div>
<div><p>this is the next page of the article blabla ...</p></div>

我尝试了不同的想法,但没有用。我如何使用 Javascript 或 JQuery(或其他方法 ;-))做到这一点?

最佳答案

使用拆分创建数组并循环创建 div。

var html = "<p>This is an article bla bla</p> <hr/> <p>this is the next page of the article blabla ...</p>";


$(html.split('<hr/>')).each(function(){
$('#test').append('<div>'+this+'</div>')
})

Demo

关于javascript - 使用基于 HR 标签的 Javascript/JQuery 在 div 中拆分 HTML,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8103485/

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