猿问

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

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


<?php


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


?>


长风秋雁
浏览 176回答 1
1回答

慕沐林林

您需要转义HTML双引号:echo&nbsp;"<button&nbsp;onclick=\"location.href='phpfile.php';\">My&nbsp;Button</button>";或者 Javascript 单引号:echo&nbsp;'<button&nbsp;onclick="location.href=\'phpfile.php\';">My&nbsp;Button</button>';顺便一提,此页面不工作。表示 500 错误,这意味着您的php脚本无法编译。大多数时候是由于语法错误。
随时随地看视频慕课网APP
我要回答