我在下面有一个php html代码
<div class="btn form-bttn1" style="width:auto; float:right;"><a href=<?php if($rowHO->hotel_booking_type==2){$checkin=date('Y-m-d',strtotime($check_in));
$checkout=date('Y-m-d',strtotime($check_out)); ?>"https://secure.booking.com/book.html?aid=870045&hostname=www.safarion.com&stage=1&checkin=<?php echo $checkin; ?>&checkout=<?php echo $checkout; ?>&maxrooms=1&hotel_id=<?php echo $rowHO->hotel_hotels_id; ?>" target=_blank<?php }else{ ?>"javascript:submitform(myForm,<?php echo $rowHO->hotel_id; ?>,'<?php echo $rowHO->hotel_name; ?>')"
<?php } ?>>Choose your room </a></div>
javascript:submitform(myForm,<?php echo $rowHO->hotel_id; ?>,'<?php echo $rowHO->hotel_name; ?>')
这里hotel_name包含单引号。
因此显示错误
参数列表之后的Uncaught SyntaxError:missing) 提交表格(myForm,79,雷迪森的Blu Resort Temple Bay)
答案 0 :(得分:0)
使用反斜杠,例如:
<?php
echo '\''; //Output will be ' ;
// OR
echo "\""; //Output will be "" ;
?>
答案 1 :(得分:0)
使用addslashes来转义字符
$hotel_name = "Hotel O'Broy!";
// Outputs: Hotel O\'Broy!
echo addslashes($hotel_name );