2017-09-29 17 views
0

PHPなしで実行すると、うまく動作します。PHPでJavaScriptを実行するとUncaught SyntaxErrorが発生する

 <?php 

     $it="$getuser[active]"; if($it==1) 
     { echo '<script type="text/javascript">'; 
     echo ' $(document).ready(function() { 
     var unique_id = $.gritter.add({ 
     // (string | mandatory) the heading of the notification 
     title: "Welcome to my website!", 
     // (string | mandatory) the text inside the notification 
     text: "Activate Your Account Now!!<a href="active.php" target="_blank" style="color:#ffd777">Click Here</a>.", 
     // (string | optional) the image to display on the left 
     image: "img.jpg", 
     // (bool | optional) if you want it to fade out on its own or just 
     sit there 
     sticky: true, 
     // (int | optional) the time you want it to be alive for before 
     fading out 
     time: "", 
     // (string | optional) the class name you want to apply to that specific message 
     class_name: "my-sticky-class" 
    });'; 

     echo ' return false; 
    });'; 
    echo '</script> '; 
    } 
    ?> 
+2

なぜあなたはこれをやっていますか?コードは読めない混乱です。 'echo'を使わずにJSを直接出力するだけです。また、 'uncaught syntax error'はメッセージの半分です。残りの半分は、エラーが何であるか、そしてその行が何であるかを正確に伝えます。 –

+0

こんにちはRory私はPHP if文でこれを行いました。 PHPがなくてもうまく動作しています – yeah

+1

まさに - それをPHPに入れたのはなぜですか? –

答えて

1

"をエスケープする必要があります。 text: "Activate Your Account Now!!<a href="active.php" target="_blank" style="color:#ffd777">Click Here</a>.",この行はまた、「そこに座って」の前に改行を削除し、

<?php 
$it="$getuser[active]"; if($it==1) 
{ 
    echo '<script type="text/javascript">'; 
    echo ' $(document).ready(function() { 
    var unique_id = $.gritter.add({ 
     // (string | mandatory) the heading of the notification 
     title: "Welcome to my website!", 
     // (string | mandatory) the text inside the notification 
     text: "Activate Your Account Now!!<a href=\"active.php\" target=\"_blank\" style=\"color:#ffd777\">Click Here</a>.", 
     // (string | optional) the image to display on the left 
     image: "img.jpg", 
     // (bool | optional) if you want it to fade out on its own or just sit there 
     sticky: true, 
     // (int | optional) the time you want it to be alive for before fading out 
     time: "", 
     // (string | optional) the class name you want to apply to that specific message 
     class_name: "my-sticky-class" 
    });'; 

    echo ' return false; 
    });'; 
    echo '</script> '; 
} 
?> 

EDIT

を「フェードアウト」あなたはまた、PHPの部分をスキップし、ちょうど直接

<?php 
$it="$getuser[active]"; if($it==1) 
{ ?> 
    <script type="text/javascript"> 
    $(document).ready(function() { 
    var unique_id = $.gritter.add({ 
     // (string | mandatory) the heading of the notification 
     title: "Welcome to my website!", 
     // (string | mandatory) the text inside the notification 
     text: 'Activate Your Account Now!!<a href="active.php" target="_blank" style="color:#ffd777">Click Here</a>.', 
     // (string | optional) the image to display on the left 
     image: "img.jpg", 
     // (bool | optional) if you want it to fade out on its own or just sit there 
     sticky: true, 
     // (int | optional) the time you want it to be alive for before fading out 
     time: "", 
     // (string | optional) the class name you want to apply to that specific message 
     class_name: "my-sticky-class" 
    }); 

    return false; 
    }); 
    </script> 
<?php } 
?> 
をするスクリプトを書くことができ、問題を作成します。
+0

魅力のような素晴らしい仕事。まさに私が欲しいものありがとう – yeah

関連する問題