在PHP中获取错误回显javascript

Spi*_*lot 2 javascript php echo

我得到一个错误,在线selection = ui.item.addClass等地方存在语法问题..但我无法弄清楚它是什么.我想我已经逃脱了所有正确的引用,但我不确定.注意:前两个变量意味着包含空的单引号.

<?php      
echo    "<script>";

echo    "$(function(){";


echo  "var selection = \' \'; ";

echo  "var selectClass = \' \'; ";

echo  " $(\".menu\").menu({ ";

echo  " select: function (event, ui) { "
echo   " $(\'.selected\', this).removeClass(\'selected\'); ";
echo     "  selection = ui.item.addClass(\'selected\').children(\'a\').attr(\'name\');";


echo  " }"; // closes select function

echo  "  }); "; // closes menu
echo  " </script>";
?>
Run Code Online (Sandbox Code Playgroud)

Nie*_*sol 6

首先,我将简化您的代码:

<?php      
echo  <<<'SCRIPT'
<script>
$(function(){
    var selection = ' ';
    var selectClass = ' ';
    $(".menu").menu({
        select: function (event, ui) {
            $('.selected', this).removeClass('selected');
            selection = ui.item.addClass('selected').children('a').attr('name');
        } // closes select function
    }); // closes menu
}); // close function()
</script>
SCRIPT;
?>
Run Code Online (Sandbox Code Playgroud)

您会发现这个"神奇地"修复了您的问题,因为现在您没有丢失的分号;)