2013-04-06 71 views
2

我得到一個錯誤,有一個語法問題的線selection = ui.item.addClass等,但我不知道它是什麼。我想我已經逃脫了所有正確的引號,但我不確定。注意:前兩個變量是爲了包含空的單引號。獲取錯誤在PHP中回顯javascript

<?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>"; 
?> 
+0

javascript輸出中的點是'echo;'?你爲什麼不放棄你的PHP標籤然後放回去? – 2013-04-06 22:14:11

+0

你不需要''''''內'' - 一個簡單的'選擇'將工作 – karthikr 2013-04-06 22:15:43

+0

更好,但爲什麼你混合使用JavaScript與PHP?分開邏輯 – 2013-04-06 22:16:08

回答

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

你會fi nd這個「神奇」修復你的問題,因爲現在你沒有缺少分號;)

+0

lol nowdoc現在神奇:P – 2013-04-06 22:27:45

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

?> 
0
在最後一行

添加此

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

試一試:D