問題Perl変数をJavascript関数に渡すときにエラーが発生します。私は何かが足りないのですか?
print "<button onclick='return getPdf("$user");'>PDF</button>";
エラーの結果:POST page.pl 500(内部サーバーエラー)
print "<button onclick='return getPdf(".$user.");'>PDF</button>";
エラーの結果:Uncaught ReferenceError:Tom is not defined at HTMLButtonElement.onclick(page.pl:113)
print "<button onclick='return getPdf('$user');'>PDF</button>";
エラーの結果:Uncaught SyntaxError:予期しない入力の終了
print "<button onclick='return getPdf('.$user.');'>PDF</button>";
エラーの結果:Uncaught SyntaxError:予期しない入力の終了
page.pl
$user = "Tom";
print "<button onclick='return getPdf();'>PDF</button>";
Javascript
function getPdf(user) {
alert("User is: " + user);
}
これは修正です
関数に渡す必要のある変数を次のように囲みます。
\''.$variable.'\'
完全なコード:
print '<button onclick="return getPdf(\''.$user.'\');">PDF</button>';
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加