2017-09-29 18 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

你爲什麼這樣做?該代碼是一個難以理解的混亂。只需直接輸出JS而不使用'echo'。另外'未捕獲的語法錯誤'是消息的一半。另一半告訴你*確切*錯誤是什麼,以及它是什麼行 –

+0

你好羅裏我做了這個與PHP如果聲明。沒有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> '; 
} 
?> 

編輯

您也可以跳過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

相關問題