是否可以在 perl 的 here-doc 部分包含 JQuery。 我试过但没有成功。 这是我的代码。
my $cgi = CGI->new();print header();print start_html("JQuery in perl");
print <<JS;
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script><!--
$(document).ready(function(){
$("p").click(function(){
$(this).hide();
});
});
//--></script>
<p>Click to hide</p>
<p>Click to hide</p>
<p>Click to hide</p>
</body>
JS
print end_html();
但是当我写一个 javascript 函数时,它工作正常
my $cgi = CGI->new();print header();print start_html("hello");
print <<JS;
<script><!--
function show() {alert("Hello");}
//--></script>
<input type="button" value="Check" onclick="show()">
</body>
JS
print end_html();
我在这里遗漏了什么明显的东西吗?请提出建议。
最佳答案
here-doc 的工作方式类似于双引号字符串:评估变量。由于 $(
实际上是一个 variable in Perl,它将被进程的真实组 ID 替换。使用反斜杠将其转义。
关于javascript - 此处文档中的 JQuery 不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15958759/