我怎样才能用 jQuery 整理下面的这个 html 标签,
<p><em>bla bla bla<br /></em>someone</p>
进入,
<p><em>bla bla bla</em><br />someone</p>
我想让bla bla bla进入一个容器,然后有人进入另一个容器。到目前为止,我已经想出了下面的代码......
// Refresh quotes.
var quotes = $(".quote-library");
// Starts with 1.
var count = 1;
$(".button-refresh").click(function(){
var current = $("p:eq("+ count +")",quotes).text();
alert(current);
//console.log(count + 1);
// Break the string into an array with the line break.
var array = current.split("\n");
//alert(array[0]);
//console.log(count + 1);
// Put the text into the containers.
$(".quote-italic").empty().html("<em>"+ array[0] +"</em>");
$(".quote-normal").empty().html(array[1]);
// Increase the counter on each click.
count ++;
// Increase the counter on each click.
count ++;
// Reset count counter when it reaches the limit.
if(count == $("p",quotes).length) count = 0;
return false;
});
html,
<div class="quote-library" style="display:none;">
<p><em>Man is a creation of desire, not a creation of need.</em><br /> Gaston Bachelard</p>
<p><em>We are like butterflies who flutter for a day and think it's forever.</em><br /> Carl Sagan</p>
<p><em>Imagination will often carry us to worlds that never were. But without it we go nowhere.</em><br /> Carl Sagan</p>
<p><span><em>One must always maintain one's connection to the past and yet ceaselessly pull away from it.</em><br /> Jean-Paul Sartre<br /></span></p>
<p><span><em>Man is condemned to be free; because once thrown into the world, he is responsible for everything he does.</em><br /> Jean-Paul Sartre<br /></span></p>
<p><span><em>Hell is other people.</em><br /> Jean-Paul Sartre<br /></span></p>
<p><em>bla bla bla<br /></em>someone</p>
</div>
<div class="holder-quote">
<p class="quote-voltaire">
<span class="quote-italic"><i>A bottle of wine contains more philosophy than all the books in the world.</i></span>
<span class="quote-normal">Louis Pasteur</span>
</p>
<a href="#" class="button-refresh hide-text">refresh</a>
</div>