jQuery在here-doc里面不起作用 [英] JQuery inside here-doc not working
本文介绍了jQuery在here-doc里面不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
是否可以在perl的here-doc部分中包含JQuery. 我尝试过但没有成功. 这是我的代码.
Is it possible to include JQuery in the here-doc section of perl. I tried but no success. Here is my code.
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函数时,它可以正常工作
But when I write a javascript function, it works fine
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();
我在这里遗漏了明显的东西吗?请提出建议.
Am I missing something obvious here ?Please suggest.
推荐答案
here-doc的工作方式与双引号字符串相似:对变量进行求值.由于$(
实际上是 Perl中的变量,它将被进程的真实组ID代替.用反斜杠将其转义.
A here-doc works similar to a double-quoted string: variables are evaluated. As $(
is actually a variable in Perl it will get replaced by the process' real group ID. Escape it with a backslash.
这篇关于jQuery在here-doc里面不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文