在PHP中运行JavaScript,然后出现未捕获的语法错误

在PHP中运行JavaScript,然后出现未捕获的语法错误,javascript,php,jquery,Javascript,Php,Jquery,当我在没有PHP的情况下运行它时,它运行得很好 <?php $it="$getuser[active]"; if($it==1) { echo '<script type="text/javascript">'; echo ' $(document).ready(function () { var unique_id = $.gritter.add({ // (string | mandat

当我在没有PHP的情况下运行它时,它运行得很好

      <?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 }
 ?>

$(文档).ready(函数(){
var unique_id=$.grister.add({
//(字符串|必填)通知的标题
标题:“欢迎访问我的网站!”,
//(字符串|必填)通知中的文本
文本:“立即激活您的帐户!!”,
//(字符串|可选)要显示在左侧的图像
图片:“img.jpg”,
//(bool |可选)如果您希望它自己淡出或只是坐在那里
斯蒂奇:是的,
//(int |可选)您希望它在淡出之前保持活动状态的时间
时间:“,
//(字符串|可选)要应用于该特定消息的类名
班级名称:“我的粘性班级”
});
返回false;
});

为什么要这样做?代码乱七八糟。只需直接输出JS而不使用
echo
。还有一半消息是“未捕获的语法错误”。另一半告诉您错误是什么,以及错误在哪一行。Hello Rory我用php if语句做了这件事。如果没有php,它运行得很好-为什么要将它放在php中是吗?因为我查看了这个链接:-在这个通过PHP运行JavaScript的过程中。在if语句中。这不是一个好主意。事实上,我想说这是一个非常非常糟糕的主意。很棒的工作就像一个符咒。正是我想要的谢谢
<?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 }
 ?>