我想根据 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>')
})
关于javascript - 使用基于 HR 标签的 Javascript/JQuery 在 div 中拆分 HTML,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8103485/