0

こんにちは、特定のテキストを毎日表示したいのですが、次のコードのどこに問題があるのか​​ わかりません.jQueryモバイルを使用していますが、Webページでこれを実行できるのはjavascriptだと思いました.

<div data-role="content">
            <div>
            <script>
                var n = new Date().getDay();
                var ch = new String();



                switch(n)
                {
                    case 0:
                    {
                    ch = String("\“It is not so easy to leave your comfort zone, it is a very difficult thing to do, 
                    but it most certainly will change your future and make you a better person than you ever could imagine\”&lt;br><br>Today\'s challenge:<br><br>
                    Do you live in the future?<br><br>
                    Become aware of moments when you are lost in thinking about the future, whether it is 10 minutes or 2 years from now. 
                    Notice how it pulls your attention from the present moment. See the reasons why you are running from your current experience.<br>");

                    }
                    break;

                    case 1:
                    ch = String("A dream is your creative vision for your life in the future. You must break out of your current comfort zone and become comfortable with the unfamiliar and the unknown.-Denis Waitley<br><br>
                    Today\'s challenge(Do one of them, or more if you like so...):<br><br>
                    Do everyday things differently. 
                    Take a different route to work. 
                    Try a new restaurant without checking Yelp first. Go vegetarian for a week, or a month. 
                    Try a new operating system. Recalibrate your reality. 
                    Whether the change you make is large or small, make a change in the way you do things on a day-to-day basis. 
                    Look for the perspective that comes from any change, even if it\'s negative. 
                    Don\'t be put off if things don\'t work out the way you planned.");
                    break;

                    case 2:
                    ch = String("Life begins at the end of your comfort zone. -Neale Donald Walsch<br<br>
                    Today\'s challenge:<br><br>
                    ");
                    break;

                    case 3:
                    ch = String("The comfort zone is the great enemy to creativity; moving beyond it necessitates intuition, 
                    which in turn configures new perspectives and conquers fears.- Dan Stevens<br><br>
                    Today\'s challenge:<br><br>
                    Trust yourself and make snap decisions. We\'re contradicting ourselves, but there\'s a good reason. 
                    Just as there are people who thrive on snap decisions, others are more comfortable weighing all of 
                    the possible options several times, over and over again. Sometimes making a snap call is in order, 
                    just to get things moving. Doing so can help you kickstart your personal projects and teach you to trust your judgement. 
                    It\'ll also show you there\'s fallout to quick decisions as well as slow ones.");
                    break;

                    case 4:
                    ch = String("Comedians tend to find a comfort zone and stay there and do lamer versions of themselves for the rest of their career.- Chris Rock<br><br>
                    Today\'s challenge:<br><br>
                    Take your time making decisions. 
                    Sometimes slowing down is all it takes to make you uncomfortable—especially if speed and 
                    quick thinking are prized in your work or personal life. Slow down, 
                    observe what\'s going on, take your time to interpret what you see, and then intervene. 
                    Sometimes just defending your right to make an educated decision can push you out of your comfort zone. 
                    Think, don\'t just react.");
                    break;

                    case 5:
                    ch = String("I think when you get people who are really talented and you take them out of their comfort zone, you get a lot more out of them.- Gore Verbinski<br><br>
                    Today\'s challenge:<br><br>
                    Do it in small steps. It takes a lot of courage to break out of your comfort zone. 
                    You get the same benefits whether you go in with both feet as you do if you start slow, so don\'t be afraid to start slow. 
                    If you\'re socially anxious, don\'t assume you have to muster the courage to ask your crush on a date right away, 
                    just say hello to them and see where you can go from there. Identify your fears, and then face them step by step.");
                    break;

                    case 6:
                    ch = String("When you go out of your comfort zone and it works there's nothing more satisfying.- Kristen Wiig<br><br>
                    Today\'s challenge:<br><br>
                    Be aware of attachment to objects<br><br>
                    Notice your attachments to objects such as a cool sweater, a new gadget or any other thing that would make you feel bad if you lost it. 
                    What is the deep reason for being attached to them? Can you find the strength to let go of the attachment and give the object away?");
                    break;
                }

                document.write("<p>" + ch.big() + "</p>");
            </script>
            </div>
            <form>
                <label for="textarea-1">Post on Facebook:</label>
                <textarea cols="40" rows="8" name="textarea-1" id="textarea-1" >
                </textarea>
            </form>

            <input type="submit" value="Post to Facebook">
        </div><!-- /content -->
4

2 に答える 2

0

Javascript はすべての新しい行を個別のステートメントとして扱い、複数行の文字列を使用しています

したがって\、string(..) の行の両端で使用して、1 つの文字列にします。

\このデモフィドルを編集して追加しました

于 2013-09-15T17:26:09.210 に答える
0

いくつかのことがあります。シャドウが言ったように、複数行の文字列が適切に処理されるようにする必要があります。またcase 0:、主節を囲む中括弧は必要ありません。あなたは他の場合にそれらを正しく持っています。

少しでも楽になれる提案をさせていただきます。必要な情報をオブジェクトの配列に保持します。

obj = {

  0: [
    'day one',
    'this is what\'s happened',
    'we\'re separating up the text so that we keep the line lengths manageable'
  ],

  1: [
    'blah blah',
    'blah blah'
    ]

};

次に、あなたがしなければならないことは次のとおりです。

var n = new Date().getDay();
var info = obj[n].join('');
document.write("<p>" + info.big() + "</p>");
于 2013-09-15T17:49:31.727 に答える