window.open 在 echo 中不工作

window.open is not working inside echo

我正在尝试将 onclick="window.open()" 添加到 <? Echo "<a></a>" ?>

我的代码:

<?php
echo "<a href='$path'
    onclick='window.open('" .$path. "',
                         'newwindow',
                         'width=300,height=250');
              return false;''
 >Pop</a>";

我对外部引号有疑问 Echo 我的代码工作得很好,但由于引号更改,内部代码无法正常工作。

有解决办法吗?

\" 转义引号,这样结束:

<?php
echo "<a href=\"".$path."\" 
         onclick=\"window.open('" .$path. "', 'newwindow', 'width=300,height=250');return false;
     \">
         Pop
     </a>";
<a href='<?= $path ?>' onclick='window.open("<?= $path ?>", "newwindow", "width=300,height=250"); return false;'>Pop</a>

echo also has a shortcut syntax, where you can immediately follow the opening tag with an equals sign. Prior to PHP 5.4.0, this short syntax only works with the short_open_tag configuration setting enabled.

The major differences to print are that echo accepts an argument list and doesn't have a return value.

阅读Material

echo

您已经在 :

中写了两个单引号
... onclick='window.opened('  ....


并且它会导致回显的字符串从第二个 qoute 位置被破坏,当你想写 quotes.do 时,你可以使用 \" 代替:

<?php echo "<a href='$path'<
onclick=\"window.open(' " .$path. " '.....
....`'width=300,height=250')\";