php和javascript的报价问题

Quotes issue with php and javascript

本文关键字:问题 javascript php      更新时间:2023-09-26

我需要帮助修复以下字符串的语法错误:

<?php echo do_shortcode('[computer_tablet]<a href="URL" class="btn btn-blue" style="margin-left: 6px;" onclick="javascript:void window.open('URL','1372423739702','width=300,height=320,toolbar=0,menubar=0,location=0,status=1,scrollbars=1,resizable=0,left=0,top=0');return false;">Words</a>[/computer_tablet]'); ?>

感谢

您在参数字符串中使用的引号与用于定义字符串的开始和结束的引号相同。因此,当代码编译时,字符串从"[computer..."开始,到"windows.open("结束。每当使用与字符串开头和结尾相同的引号时,都需要使用转义引号''

<?php echo do_shortcode('[computer_tablet]<a href="URL" class="btn btn-blue" style="margin-left: 6px;" onclick="javascript:void window.open(''URL'',''1372423739702'',''width=300,height=320,toolbar=0,menubar=0‌​,location=0,status=1,scrollbars=1,resizable=0,left=0,top=0'');return false;">Words</a>[/computer_tablet]'); ?>

注意到每个单引号前的反斜杠了吗?

window.open(''URL'', ''etc...转义引号