在我的文件中,javascript中有PHP,用于添加行HTML。 在我当前的脚本下面:
$(document).ready(function(){
var i=1;
$("#add_row").click(function(){
$('#addr'+i).html("<td>"+ (i+1) +"</td><td><select name='room_manager_id["+i+"]' class='form-control' ><option value=''>--Choose--</option><?php
foreach ($resultCompany as $rowx) {
?><optgroup label='<?php echo $rowx->company_name?>'><?php
$resultType = $this->md_calendar_view->selectAllRoomAvailable($start_date,$end_date,$rowx->company_id)?><?php
foreach ($resultType as $row) {
?><option value='<?php echo $row->room_manager_id?>'><?php echo $row->room_manager_name." - ".$row->room_type_name." - ".$row->capacity_name." (".$row->capacity_number.") - ".$row->room_available." room(s) left";?></option><?php
} ?><?php
} ?></optgroup></select></td><td><input type='text' name='booking_total_rooms["+i+"]' class='form-control'> </td>");
$('#tab_logic').append('<tr id="addr'+(i+1)+'"></tr>');
i++;
});
$("#delete_row").click(function(){
if(i>1){
$("#addr"+(i-1)).html('');
i--;
}
});
导致Uncaught SyntaxError:意外的令牌ILLEGAL 但是,当我删除一些PHP脚本(只是为了查看它是一个错误)它完美的工作。我删除了这部分:
<?php foreach ($resultType as $row) { ?><option value='<?php echo $row->room_manager_id?>'><?php echo $row->room_manager_name." - ".$row->room_type_name." - ".$row->capacity_name." (".$row->capacity_number.") - ".$row->room_available." room(s) left";?></option><?php } ?>
问候和感谢。