使用基于HR标记的Javascript / JQuery在div中拆分HTML
我想基于HR标签分割我从不同DIV中的Web服务收到的文章(= HTML内容)。
我用一个例子解释,这是我从服务中收到的:
This is an article bla bla
this is the next page of the article blabla ...
我想根据HR标签制作:
This is an article bla bla
this is the next page of the article blabla ...
我试过不同的想法,但是没有用。 我怎么能用Javascript或JQuery(或另一种方法;-))来做到这一点?
使用split创建和数组并循环创建div。
var html = "This is an article bla bla
this is the next page of the article blabla ...
"; $(html.split('
')).each(function(){ $('#test').append(''+this+'') })
演示
试试 –
var html = 'This is an article bla bla
this is the next page of the article blabla ...
' var htmlarr = html.split('
'); html = html.replace(/
/g,''); $('body').append(html);
这将删除所有
然后将剩余的contnet附加到页面。我认为如果不执行split
就能达到你想要的效果。 你可以做这样的分裂 –
var htmlarr = html.split('
');
这会留下一个数组,其中包含您在问题中列出的两位HTML。 您可以使用以下方法将其添加到您的页面
$.each(htmlarr,function (index,value) { $('body').append(value); });