数据表jQuery的$(文件)。就绪没有工作,用数字
我试图启动一个实例数据表用下面的代码替换...
<script type="text/javascript" language="javascript" class="init">
$(document).ready(function() {
$('#example').DataTable();
});
</script>
但是当我通过网络的访问HTML浏览器显示的“未捕获的SyntaxError:意外的数字”错误,这是源从浏览器的外观...
<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的src和来自其CDN的DataTables JavaScript。
我从使用CGI的Perl脚本创建HTML,打印Content-type:text/html标题并使用不同的!DOCTYPE ...但仍然没有任何内容。编辑代码显示没有隐藏的字符。
您的帮助将不胜感激。
最好, e。
编辑:这是Perl代码创建HTML ...
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字符串中包含的特殊变量$(
:
$(document).ready(function() {
$('#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 bygetgroups()
, one of which may be the same as the first number.
您的字符串中的每个匹配项$(
都将替换为您的Web服务器用户所属的GID列表。
你可以看到这个命令行:
perl -wE 'say qq{$(document).ready(function()}'
输出我的系统上
3000 3000document).ready(function()
。
使用q
而不是qq
来避免将事物插入为Perl变量。
或者,如果你确实想要插入一些变量,请转义每个不能启动变量的'$'(例如'\ $(document).ready') – ysth 2014-12-02 23:24:00
另一个我用过的替代方法是,改变你的jQuery onReady,你可能无论如何都应该使用'jQuery(function(jQ){...'),然后在你使用'$'的地方使用'jQ'。 – Ashley 2014-12-03 03:31:48
@Ashley当你开始混淆你的JavaScript代码时,你可能应该看看把它放在单独的静态文件中,或者使用[模板工具包](http://www.template-toolkit.org/)这样的模板系统。 – ThisSuitIsBlackNot 2014-12-03 15:45:11
class init是做什么的? – 2014-12-02 22:42:09
请显示生成HTML的Perl代码。 – ThisSuitIsBlackNot 2014-12-02 22:44:41
@ Bhojendra-C-LinkNepal不确定,是所有尝试之一,但是在原始DataTables示例文件之一。 – Emiliano 2014-12-02 22:57:18