【问题标题】:JQuery inside here-doc not working此处文档中的 JQuery 不起作用
【发布时间】:2013-04-04 05:41:19
【问题描述】:

是否可以在 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();

我在这里遗漏了什么明显的东西吗?请提出建议。

【问题讨论】:

  • 应该可以。如果您直接拨打 jQuery 会发生什么。例如:jQuery.method() 而不是 $()

标签: javascript jquery perl cgi heredoc


【解决方案1】:

here-doc 的工作方式类似于双引号字符串:评估变量。由于$( 实际上是variable in Perl,它将被进程的真实组ID 替换。用反斜杠转义它。

【讨论】:

  • 这就是问题所在。不错的收获
  • 或者使用“单引号的HEREDOC”。 print &lt;&lt;'JS';
  • 或者使用模板系统。
猜你喜欢
  • 2012-01-17
  • 1970-01-01
  • 1970-01-01
  • 2012-10-23
  • 1970-01-01
  • 2011-12-30
  • 2018-05-04
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多