我使用Jquery脚本制作一个下拉div。
$("#top<?php echo $this->$i?>").click(function(){
$("#down<?php echo $this->$i?>").slideToggle("slow","swing",500);
});
});
这会在Google Chrome中出现语法错误。在检查员中,它显示为“#top
.Bellow one is work fine。
$("#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>
答案 0 :(得分:1)
<?php echo $this->$i?>
实际应该是
<?php echo $this->i ?>
没有$
i
符号