0

以下のこのhtmlタグをjQueryで整理するにはどうすればよいですか?

<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>
4

1 に答える 1

0

Notepad++ の問題ではありません。JavaScript 構文の問題です。質問の構文の強調表示も少しずれていることがわかります。

その HTML フラグメントは、スクリプト内で文字列データとして使用しているため、文字列にする必要があります。ここにコードを入力してください$("body").append('');

div タグも引用符で囲む必要があると思います。

append("div id=\"my_id\">");

于 2013-07-10T13:44:31.887 に答える