0

我有一个 html 页面,上面有这个。

var accountid = getParameterByName("AccountId");
var account = null;

if (accountid != null)
{
    account = GetEntity("Account", accountid, "Name, piv_BusinessUnit, AccountId");
}

在同一页的底部是这个

<script src="js/datasource.CRM.js"></script>

在那个文件中是这个

function GetEntity(logicalName, id, columnSet)
{
    return RunQuery(logicalName + "Set?&$filter="+logicalName+"Id eq guid'{" + id + "}'" + "&$select="+columnSet);
}

运行页面时出现此错误

Uncaught ReferenceError: GetEntity is not defined

有谁知道为什么找不到Javascript函数的任何原因???

4

1 回答 1

1

当包含加载外部脚本的脚本标签时,它们只会在 DOM 中遇到时被解析,因此提升不会跨脚本标签起作用。

换句话说,在实际尝试使用它之前,您必须包含该脚本。

这是classis示例,在包含之前使用jQuery,但失败了

<script type="text/javascript">
  $('#epic fail').addClass('wont_work'); // $ is not defined error
</script>

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

于 2017-09-19T00:32:39.497 回答