将 onClick 操作放入 echo 语句中的语法
以下 onClick 属性的正确语法是什么:
<?php
if($_resp['user']) {
echo '<div class="logo"><a href="http://www.example.com/" onClick="_gaq.push(['_trackEvent', 'Join', 'Home', 'BigButton']);">Link Text</a>';
}
?>
What would be the correct syntax for the onClick attribute in the following:
<?php
if($_resp['user']) {
echo '<div class="logo"><a href="http://www.example.com/" onClick="_gaq.push(['_trackEvent', 'Join', 'Home', 'BigButton']);">Link Text</a>';
}
?>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

发布评论
评论(3)
离鸿2024-12-08 00:36:09
考虑使用 HEREDOC
if ($_resp['user']) {
echo <<<EOL
<div class="logo"><a href="http://www.example.com/" onClick="_gaq.push(['_trackEvent', 'Join', 'Home', 'BigButton']);">Link Text</a>
EOL;
}
或退出 PHP 模式:
if ($_resp['user']) { ?>
<div class="logo"><a href="http://www.example.com/" onClick="_gaq.push(['_trackEvent', 'Join', 'Home', 'BigButton']);">Link Text</a>
<?php }
两者都能完成工作,并消除在生成的 html/javascript 中转义引号的需要
~没有更多了~
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
由于您同时嵌套双引号和单引号,因此您需要使用反斜杠对
onClick
中的单引号进行转义。Since you are nesting both double and single quotes, you will need to escape the single quotes in the
onClick
with backslashes.