如何在php中添加'生成的链接

时间:2017-06-06 10:14:44

标签: javascript php html

$output .= '<a class="dropdown-toggle has-category" data-toggle="dropdown" href="'.$this->getLink($menu).'" target="'.$menu['target'].'">';

我的php文件包含此代码href="'.$this->getLink($menu).'"

它在html中生成href="https://www.myweb.com/"

现在我需要使用onClick进行操作,以便输出结果如此

onclick="location.href='https://www.myweb.com'"

更改了PHP代码onclick="location.href='.$this->getLink($menu).'"

,结果为onclick="location.href=https://www.myweb.com" 链接不工作因为缺乏' 有人能帮助我吗?

2 个答案:

答案 0 :(得分:0)

您可以添加此转义单引号:\'吗?

echo '...onclick="location.href='.$this->getLink($menu).'\'"...';

(我添加了echo来完成代码示例。)

答案 1 :(得分:0)

试试这个

onclick="location.href=\''.$this->getLink($menu).'\'">

示例: -

echo '<a onclick="location.href=\''.$this->getLink($menu).'\'">';