如何将 html href 按钮放在 php 代码中

jl1126

我试图在我的 php 代码中放置一个 html href 按钮,但是当我运行它时,我收到一条错误消息,指出“此页面无法正常工作”。

<?php

echo "<button onclick="location.href='phpfile.php';">My Button</button>";

?>
弗朗索瓦·胡佩

您需要转义HTML双引号:

echo "<button onclick=\"location.href='phpfile.php';\">My Button</button>";

或者 Javascript 单引号:

echo '<button onclick="location.href=\'phpfile.php\';">My Button</button>';

顺便一提,

此页面不工作。

表示 500 错误,这意味着您的php脚本无法编译。大多数时候是由于语法错误。

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章