【发布时间】:2018-10-21 10:10:28
【问题描述】:
问题 将 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 在 HTMLButtonElement.onclick (page.pl:113)
print "<button onclick='return getPdf('$user');'>PDF</button>";导致错误:Uncaught SyntaxError: Unexpected end of input
print "<button onclick='return getPdf('.$user.');'>PDF</button>";导致错误:Uncaught SyntaxError: Unexpected end of input
page.pl
$user = "Tom";
print "<button onclick='return getPdf();'>PDF</button>";
Javascript
function getPdf(user) {
alert("User is: " + user);
}
【问题讨论】:
-
尝试使用
q(...)函数引用q|<button> onclick='return getPdf(| . $user . q|);'>PDF</button>|; -
替换:打印"";用:q||;该按钮现在甚至没有出现
-
试试ikegami的建议
-
我找到了解决办法!
标签: javascript html perl