Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/455.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
无法在PHP页面上使用javascript_Javascript_Php - Fatal编程技术网

无法在PHP页面上使用javascript

无法在PHP页面上使用javascript,javascript,php,Javascript,Php,我不确定这段代码是否有问题,但我可以让它在纯HTML页面上工作,但在PHP HTML页面上使用javascript(javascript:openDocument)时就不行了 <a id='edit' href='javascript:openDocument('asd.docx')' name='Btn1'>Edit</a> 尝试下面的代码 <a id='edit' href="javascript:openDocument('asd.docx');" nam

我不确定这段代码是否有问题,但我可以让它在纯HTML页面上工作,但在PHP HTML页面上使用javascript(javascript:openDocument)时就不行了

<a id='edit' href='javascript:openDocument('asd.docx')' name='Btn1'>Edit</a>

尝试下面的代码

<a id='edit' href="javascript:openDocument('asd.docx');" name='Btn1'>Edit</a>

也更喜欢HTML中的双引号

对于PHP:

echo "<a href=\"javascript:openDocument('asd.docx')\";>";
echo”“;

如评论中所述,您需要克服在href部分中有两个单引号的问题。为什么?当你到达第二个“点”时,它认为你就要结束了。您可以这样做:

<a id="edit" href="javascript:openDocument('asd.docx');"> 


href='javascript:openDocument('asd.docx')”
==>
href='javascript:openDocument(\'asd.docx\')”)
。注意
\'
escapingHi感谢您的回复,我试过了,但也不起作用。。突出显示超链接时收到的错误消息是“javascript.openDocument(\”没有引用。你只是直接复制并粘贴到你的PHP脚本中吗?它需要被回响,或者你需要使用?>,输入html,然后用重新打开PHP脚本。如果你想在PHP中添加纯html,那么只需关闭PHP标记并放入纯html。嗨,mfisher91。是的,我在PHP b上回响它但它仍然不起作用,我目前使用的代码是echo“echo”;谢谢,但它仍然不起作用..当我突出显示URL时,它会在IE的状态栏上显示一条消息,如javascript:openDocument('asd.docx')-当我单击它时它不会打开..它什么都不做..当我使用HTML时应该有。。