如何在php中嵌入的javascript中连接变量?

I'm using the following code but it is not concatenating the "show" and X although X is defined as var X=1.

echo"  <li class=\"\" id=\"frame\"
onClick=\"ballFunctions[\"show\"+X]();\"><a href=\"#\"> <b> $value</b>
</a> </li> <script type=\"text/javascript\"> X++; </script>  ";

Is there any syntax problem?

I don't know if your code is correct, but here is the code:

echo '  <li class="" id="frame"
onClick="ballFunctions[\'show\'+X]();"><a href="#"> <b> '.$value.'</b>
</a> </li> <script type="text/javascript"> X++; </script>  ";

Here X seems to be a JS variable...

Generally, it's better to avoid mixing PHP and js as much as you can, and/or try to group it as much as you can. Where it's unavoidable, I use single quotes to concat js and double quotes for PHP.

It looks like your code might be echoing out of a loop in PHP, is that correct? If so, you could just increment X with PHP instead,...would be faster, simpler, more readable and you wouldn't need to concat js at all.

echo "<li class=\"\" id=\"frame\" onClick=\"ballFunctions['show".$X."']();\"><a href=\"#\"><b>".$value."</b></a></li>";
$X++;