本文介绍了使用基于HR标记的Javascript / JQuery在div中拆分HTML的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想基于HR标签分割我从不同DIV中的Web服务收到的文章(= HTML内容)。
I want to split articles (= HTML content) that I receive from a webservice in different DIVs, based on a HR tag.
我用一个例子来解释,这是我从服务中收到的信息:
I explain with an example, this is what I receive from the service:
<p>This is an article bla bla</p> <hr/> <p>this is the next page of the article blabla ...</p>
我想根据HR标签制作:
I want to make, based on the HR-tag:
<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(或使用其他方法; - ))?
I tried different thinks but is doesn't work. How can I do that with Javascript or JQuery (or with another method ;-))?
推荐答案
使用split来创建和数组并循环创建div。
Use split to create and array and loop through to create the divs.
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>')
})
这篇关于使用基于HR标记的Javascript / JQuery在div中拆分HTML的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!