gpt4 book ai didi

javascript - 在 cgi.pm 中包含内部 javascript

转载 作者:行者123 更新时间:2023-11-28 15:56:55 27 4
gpt4 key购买 nike

我想在 cgi.pm 文件中添加 jquery datepicker,并想为 datepicker 添加内联脚本 jquery 标记,因为它在外部 javascript 文件中不起作用。这个怎么加啊。。我必须使用 cgi.pm,因为我被告知在我的工作场所这样做,而不是选择...

ivalid.js 和 sthome.css 中的代码运行良好...

这是我想在cgi文件内部添加的功能。

$( function() {
$( "#datepick" ).datepicker({ minDate: 0, maxDate: "+1M +10D" });
} );

cgi.pm

$q->start_html
(
-title=>'ai',
-style=>[{'src'=>'/sthome.css'},
{'src'=>'//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css'},
{'src'=>'/resources/demos/style.css'}],
-script=>[{-language=>'javascript',
-src=>'/ivalid.js'},
{-language=>'javascript',
-src=>'https://code.jquery.com/jquery-1.12.4.js'},
{-language=>'javascript',
-src=>'https://code.jquery.com/ui/1.12.1/jquery-ui.js'}
]
),

最佳答案

如果我正确理解你的问题,你需要做的就是在 -script=>[...] 数组中包含一个字符串:

use warnings;
use strict;
use CGI;

my $q = CGI->new;

my $JAVASCRIPT = <<'ENDJS';
$( function() {
$( "#datepick" ).datepicker({ minDate: 0, maxDate: "+1M +10D" });
} );
ENDJS

print $q->start_html(
-title=>'Baseline Automation Input',
-style=>[ {'src'=>'/sthome.css'}, ],
-script=>[
{-language=>'javascript', -src=>'/ivalid.js'},
$JAVASCRIPT,
],
);

输出:

<!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en-US" xml:lang="en-US">
<head>
<title>Baseline Automation Input</title>
<link rel="stylesheet" type="text/css" href="/sthome.css" />
<script src="/ivalid.js" type="text/javascript"></script>
<script type="text/javascript">//<![CDATA[
$( function() {
$( "#datepick" ).datepicker({ minDate: 0, maxDate: "+1M +10D" });
} );

//]]></script>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
</head>
<body>

关于javascript - 在 cgi.pm 中包含内部 javascript,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48734859/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com