JQuery inside here-doc not working

时光总嘲笑我的痴心妄想 提交于 2019-12-11 02:33:04

问题


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();

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.


回答1:


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.



来源:https://stackoverflow.com/questions/15958759/jquery-inside-here-doc-not-working

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!