[英]Using Perl mason variables in Javascript
Let's say I have a variable called $taskid
defined in <%init>
. 假设我在<%init>
定义了一个名为$taskid
的变量。 Can I generate a JavaScript function from that variable? 我可以从该变量生成JavaScript函数吗?
<script language="javascript">
window.onload = function() {
alert("<% $taskid %>");
};
</script>
<%init>
my $taskid=1;
</%init>
This worked: 这工作:
<script language="javascript">
window.onload = function() {
alert("<% $taskid %>");
};
</script>
<%init>
my $taskid=1;
</%init>
Is it possible to initialize a JavaScript variable from Perl? 是否可以从Perl初始化JavaScript变量?
Since you asked that three times even though it has nothing to do with what you posted, I'll answer it. 尽管您问过三遍,即使这与您发布的内容无关,我也会回答。
No. 没有。
Languages can't take actions, much less initialize. 语言无法采取行动,更不用说初始化。 A Perl program cannot do so either. Perl程序也不能这样做。 A process cannot access variables a) in a different virtual machine, b) in a different process, c) on a different machine. 进程无法访问变量a)在不同的虚拟机中,b)在不同的进程中,c)在不同的计算机上。 All three apply here. 这三个都适用于此。
JavaScript variables can only be initialized by JavaScript assignments. JavaScript变量只能通过JavaScript分配进行初始化。 You would need to either 您将需要
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.