我正在尝试运行以下文件。当我在本地驱动器上运行它时,它运行得很好,但如果我将它放在网络驱动器上,它就不再工作。知道为什么会这样吗?
下面是我尝试运行的代码。它使用这里的数据透视表:https://github.com/nicolaskruchten/pivottable 。
<!DOCTYPE html>
<html>
<head>
<title> Demo</title>
<!-- external libs from cdnjs -->
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jqueryui/1.11.4/jquery-ui.min.js"></script>
<!-- PivotTable.js libs from ../dist -->
<link rel="stylesheet" type="text/css" href="../dist/pivot.css">
<script type="text/javascript" src="../dist/pivot.js"></script>
<style>
body {font-family: Verdana;}
</style>
<!-- optional: mobile support with jqueryui-touch-punch -->
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jqueryui-touch-punch/0.2.3/jquery.ui.touch-punch.min.js"></script>
</head>
<body>
<script type="text/javascript">
// This example shows custom aggregators using
$(function(){
var tpl = $.pivotUtilities.aggregatorTemplates;
$.getJSON("col.json", function(frontier) {
$("#output").pivotUI(frontier, {
rows: ["Manager"], cols: ["Sector"],
aggregators: {
"Number of Positions": function() { return tpl.count()() },
"Manager Weight": function() { return tpl.sum()(["Port"])},
"Benchmark XGCC Weight": function() { return tpl.sum()(["Bench"])},
}
});
});
});
</script>
<div id="output" style="margin: 30px;"></div>
</body>
</html>
最佳答案
File:///
url 将在与 HTTP/HTTPS 和其他上下文(内部、公共(public)、私有(private)、不安全)不同的上下文中运行。所讨论的限制取决于特定的浏览器、操作系统和上下文本身。
如果您必须在 HTML 中执行 JavaScript,最安全、最可靠的运行方式是通过 Web 服务器运行它。
<小时/>还值得注意的是,有一些本地/相对文件。 ../dist/pivot.js
和 ../dist/pivot.css
您确定要保存这些文件,并且它们也位于正确的相对路径中吗?
关于javascript 无法从网络驱动器运行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39460872/