gpt4 book ai didi

jquery - Datatables jQuery $(document).ready 不工作并被数字取代

转载 作者:搜寻专家 更新时间:2023-10-31 08:17:49 25 4
gpt4 key购买 nike

我正在尝试使用以下代码启动 DataTables 实例...

<script type="text/javascript" language="javascript" class="init">
$(document).ready(function() {
$('#example').DataTable();
} );
</script>

但是当我通过网络访问 HTML 时,浏览器显示一个“Uncaught SyntaxError: Unexpected number” 错误,这就是源代码从浏览器看起来的样子......

<script type="text/javascript" language="javascript" class="init">
0 11 4 3 2 1 0document).ready(function() {
0 11 4 3 2 1 0'#example').DataTable();
} );
</script>

如您所见,一些指令已被数字“0 11 4 3 2 1”取代,我不知道是什么原因造成的。

jQuery 来自 Google,而 DataTables javascript 来自他们的 CDN。

我正在使用 CGI 从 Perl 脚本创建 HTML,打印 Content-type:text/html header 并使用不同的 !DOCTYPEs... 但仍然没有。编辑代码显示没有隐藏字符。

非常感谢您的帮助。

最好的,即.

编辑:这是创建 HTML 的 Perl 代码...

use Switch;
use CGI qw/:standard/;
use CGI::Carp 'fatalsToBrowser';

print "Content-type:text/html\r\n\r\n";

print qq{<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="initial-scale=1.0, maximum-scale=2.0">
<link rel="stylesheet" type="text/css" href="css/jquery.dataTables.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js"></script>
<script language="JavaScript" type="text/javascript" src="js/jquery.dataTables.min.js"></script>
<script type="text/javascript" language="javascript">
/* <![CDATA[ */
$(document).ready(function() {
$('#example').DataTable();
} );
/* ]]> */
</script>
</head>};

最佳答案

问题是 qq 插入变量并且您的 HTML 字符串包含特殊变量 $(:

<b>$(</b>document).ready(function() {
<b>$(</b>'#example').DataTable();

根据perldoc perlvar:

$(

The real gid of this process. If you are on a machine that supports membership in multiple groups simultaneously, gives a space separated list of groups you are in. The first number is the one returned by getgid(), and the subsequent ones by getgroups(), one of which may be the same as the first number.

字符串中每次出现的 $( 都会替换为您的网络服务器用户所属的 GID 列表。

你可以在命令行上看到这个:

perl -wE 'say qq{$(document).ready(function()}'

输出

3000 3000document).ready(function()

在我的系统上。

使用 q 而不是 qq 以避免将内容作为 Perl 变量进行插值。

关于jquery - Datatables jQuery $(document).ready 不工作并被数字取代,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27260417/

25 4 0
文章推荐: javascript - 按 'j' 时滚动到下一个
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com