[英]PHP and JS help: function doesn't accept arguments pasted with echo
Here's a long code row I'm using to paste HTML via PHP: 这是我用来通过PHP粘贴HTML的一长行代码:
echo "<h2 style=\"color: white!important; background: black!important; border: 4px black solid!important;\">", $p_name, "<span id=\"portfolio-", $p_id, "\" onclick=\"expandToggle(this);\" style=\"float: right; padding-right: 10px; cursor: pointer;\">+</span>", "<span onmouseover=\"getNotify(this, true)\" onmouseout=\"getNotify(this, false)\" onclick=\"window.open(",$p_get,")\" style=\"float: right; cursor: pointer; padding-right: 15px;\">⬇</span></h2>";
$p_get is an URL, window.open(), well, opens a window. $ p_get是一个URL,window.open()会打开一个窗口。 However this is what happens if I try to use that:
但是,如果我尝试使用它,将会发生以下情况:
and a JS error in console: 和控制台中的JS错误:
Uncaught SyntaxError: missing ) after argument list
How do I fix that? 我该如何解决?
There seems to be new line ( \\n
) character around the url. 网址周围似乎有换行(
\\n
)字符。
echo "<h2 style=\"color: white!important; background: black!important; border: 4px black solid!important;\">",
$p_name, "<span id=\"portfolio-", $p_id, "\" onclick=\"expandToggle(this);\" style=\"float: right; padding-right: 10px; cursor: pointer;\">+</span>",
"<span onmouseover=\"getNotify(this, true)\" onmouseout=\"getNotify(this, false)\" onclick=\"window.open('",str_ireplace("\n", "", $p_get),"')\" style=\"float: right; cursor: pointer; padding-right: 15px;\">⬇</span></h2>";
The changed part is: 更改的部分是:
window.open('",str_ireplace("\n", "", $p_get),"')
Update: 更新:
Since your code can be difficult to read hence difficult to understand here is a better formatted solution. 由于您的代码可能难以阅读,因此在这里难以理解是一种更好的格式化解决方案。
printf(
'<h2 style="color: white!important; background: black!important; border: 4px black solid!important;">
%s
<span id="portfolio-%d" onclick="expandToggle(this);" style="float: right; padding-right: 10px; cursor: pointer;">+</span>
<span onmouseover="getNotify(this, true)" onmouseout="getNotify(this, false)" onclick="window.open(\'%s\')" style="float: right; cursor: pointer; padding-right: 15px;">⬇</span>
</h2>',
$p_name, $p_id, str_replace("\n", "", $p_get)
);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.