我正在尝试使用"Etherson方法“执行一个用JavaScript创建web部件的示例。我希望自定义库中有单独的.html和.js文件,如下所示:文件
如果我将js保持在行内,代码将按预期工作:
<!DOCTYPE html><html><head>
<title></title>
<script type="text/javascript">
$(function () {
$.ajax({
url: "/mOperations/_api/web/lists/GetByTitle('Demo List')/items", type: "GET", headers: { "accept": "application/json;odata=verbose" },
}).success(function (data) {
var listItemInfo = "";
$.each(data.d.results, function (key, value) {
listItemInfo += "<strong>Title: </strong>" + value.Title + " <strong>Description: </strong>" + value.Description + "<br />";
});
$("#divHelloWorld").html(listItemInfo);
});
});
</script></head><body>
<div id="divHelloWorld">Hello World!</div></body></html>但是,如果我引用一个外部.js文件,它就好像JavaScript不存在(也就是说,它永远不会被调用):
<!DOCTYPE html>
<html">
<head>
<meta charset="utf-8" />
<title></title>
<script type="text/javascript" scr="https://mysite.sharepoint.com/mOperations/webparts/SimpleExample/SimpleExample.js"></script>
</head>
<body>
<div id="divHelloWorld">Hello Worlds!</div>
</body>
</html>我验证了路径https://mysite.sharepoint.com/mOperations/webparts/SimpleExample/SimpleExample.js是正确的。
我遗漏了什么?
发布于 2016-03-07 07:33:31
您需要将html中的"scr“更改为"src”。
<script type="text/javascript" scr="your_js_file.js"></script>至
<script type="text/javascript" src="your_js_file.js"></script>https://stackoverflow.com/questions/35836064
复制相似问题