在php中显示javascript变量不工作


Displaying javascript variable in php not working

我有一个代码,其中包含php代码中的javascript。问题是变量"i"没有正确显示,它被解释为"(‘calendarRandom’+ i +‘’)",但我想成为"("calendarRandom0")"、"(‘calendarRandom1’)"等等…

这是我的php代码
 $ret .= "
 <script type='text/javascript'>
 function randomCheck()
 {
    var i;
    var optionIndex = document.getElementById('randomSelect').value;
    for (i=0; i<optionIndex; i++) {
        var calendarRandom = 'calendarRandom' + i;
        document.getElementById('calendarRandom'" + i + '").style.display = 'block';
    }
 }
 </script>";

有谁知道怎么算出来的吗

<?php
$ret .= "
 <script type='text/javascript'>
 function randomCheck()
 {
    var i;
    var optionIndex = document.getElementById('randomSelect').value;
    for (i=0; i<optionIndex; i++) {
        var calendarRandom = 'calendarRandom' + i;
        document.getElementById('calendarRandom' + i).style.display = 'block';
    }
 }
 </script>";
 echo $ret;

 ?>

就是这样:)