Javascript 未找到外部方法
Javascript External Method Not Found
我有一个 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 函数存在时找不到的原因吗???
当包含加载外部脚本的脚本标签时,它们只会在 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>
我有一个 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 函数存在时找不到的原因吗???
当包含加载外部脚本的脚本标签时,它们只会在 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>