将变量添加到 Jquery 后出现语法错误


Syntax error after adding a variable into Jquery

我使用Jquery脚本制作了一个下拉div。

$("#top<?php echo $this->$i?>").click(function(){
        $("#down<?php echo $this->$i?>").slideToggle("slow","swing",500);
      });
    });

这是在谷歌浏览器中给出语法错误。在检查器中,它显示为"#top
.波纹管一个工作正常。

$("#top<?php echo "one"?>).click(function(){
        $("#down<?php echo "two"?>").slideToggle("slow","swing",500);
      });
    });

为什么会发生这种情况,如果我犯了错误,如何解决它。

这是我的 phtml 文件。

<!doctype html>
<html>
<head>
<link rel="stylesheet" type="text/css" href="mycss.css">
<script src="jquery-1.11.1.js"></script>
<script type="text/javascript">
$(document).ready(function(){
     $("#top<?php echo $this->i;?>").click(function(){
        $("#down<?php echo $this->i;?>").slideToggle("slow","swing",500);
      });
    });
</script>
</head>
<body>
<div id="container">
<div id="R_booking_container">
    <h1 id="R_booking_header">Recently Added Bookings</h1>
    <div id="left_pane">
        <ul class="left_pane_ul">
            <li class="left_pane_button"><a href="#">Facility Bookings</a></li>
            <li class="left_pane_button"><a href="#">Equipment Bookings</a></li>
            <li class="left_pane_button"><a href="#">Recurring Bookings</a></li>
        </ul>
    </div>
    <div id="right_pane">
    <?php   $datas = $this->data_array;
            $i = 0;
            foreach($datas as $datas) { 
            extract ($datas);
            $i++?>
        <div class="booking_details" id="top_box" id="top<?php echo $i?>">
            <h1 id="event_name"><?php echo $event_name;?></h1>
            <hr id="event_line"/>
            <div id="to_more_info">
                <span class="date_time">Date: <?php echo $time;?></span>
                <span class="date_time">Time: <?php echo $time;?></span>
            </div>
            <div id="drop_down_info" id="down<?php echo $i?>">
                <table id="more_b_info" border="0" width="100%">
                    <tr>
                        <td class="info"><span class="b_info">Booked By:</span></td>
                        <td class="info"><span class="b_info"><?php echo $booked_by;?></span></td>
                        <td class="info"><span class="b_info">Booking ID:</span></td>
                        <td class="info"><span class="b_info"><?php echo $booking_id;?></span></td>
                    </tr>
                    <tr>
                        <td class="info"><span class="b_info">Requested User:</span></td>
                        <td class="info"><span class="b_info"><?php echo $requested_user;?></span></td>
                        <td class="info"><span class="b_info">Payment Due Date:</span></td>
                        <td class="info"><span class="b_info"><?php echo $payment_due_date;?></span></td>
                    </tr>
                    <tr>
                        <td class="info"><span class="b_info">Booking Status:</span></td>
                        <td class="info"><span class="b_info"><?php echo $booking_status;?></span></td>
                        <td class="info"><span class="b_info">Sponsored Booking:</span></td>
                        <td class="info"><span class="b_info"><?php echo $sponsored_booking;?></span></td>
                    </tr>
                </table>
            </div>
        </div>
        <?php } ?>
    </div>
  </div>
</div>
</body>
</html>
<?php echo $this->$i?>

实际上应该是

<?php echo $this->i ?>

没有i$标志