添加onclick事件后出错

时间:2013-09-04 15:40:48

标签: php

以下是我用于返回图片的PHP代码,但我收到错误。请让我知道我做错了什么。 如果我从以下代码中删除onclick事件,则不会发生错误。

return ('<img onclick="window.open('http://google.com','_blank')" src="'.$content.'" alt=""/>');

3 个答案:

答案 0 :(得分:1)

你没有逃脱单引号:

return ('<img onclick="window.open(\'http://google.com\', \'_blank\')" src="'.$content.'" alt=""/>');

答案 1 :(得分:1)

你必须转义字符:

return ('<img onclick="window.open(\'http://google.com\',\'_blank\')" src="'.$content.'" alt=""/>');

答案 2 :(得分:0)

使用反斜杠

return ('<img onclick="window.open(\'http://google.com\',\'_blank\')" src="'.$content.'" alt=""/>');