2

我收到一个错误,即 where etc.. 行存在语法问题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>";
?>
4

4 回答 4

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

您会发现这“神奇地”解决了您的问题,因为现在您没有丢失的分号;)

于 2013-04-06T22:16:42.007 回答
4

亲自。我会退出我的 Javascript 的标签。当我完成输入后,我认为重新打开 PHP 标签以继续没有什么坏处。

 //Other code here 
?>
<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
});// closes function()
</script>

<?php 
// Continue here 

?>
于 2013-04-06T22:17:07.420 回答
1

您在第 14 行缺少分号

echo  " select: function (event, ui) { ";
echo   " $(\'.selected\', this).removeClass(\'selected\'); ";

修复它给出了这个:http ://eval.in/15236

<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\'); }  });  </script>
于 2013-04-06T22:15:53.027 回答
0

在最后一行添加这个

echo  "  }); "; // closes menu
// --- add this
echo " });";
// -----
echo  " </script>";

试试看 :D

于 2013-04-06T22:18:42.337 回答