簡體   English   中英

PHP和JS幫助:函數不接受粘貼回顯的參數

[英]PHP and JS help: function doesn't accept arguments pasted with echo

這是我用來通過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是一個URL,window.open()會打開一個窗口。 但是,如果我嘗試使用它,將會發生以下情況: 這沒東西看

和控制台中的JS錯誤:

Uncaught SyntaxError: missing ) after argument list

我該如何解決?

網址周圍似乎有換行( \\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>";

更改的部分是:

window.open('",str_ireplace("\n", "", $p_get),"')

更新:
由於您的代碼可能難以閱讀,因此在這里難以理解是一種更好的格式化解決方案。

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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM