我有一个如下的脚本,我想'命名'它,然后在我的HTML中调用它,就像这样:
<html>
<body>
<script>loadLibrary()</script>
</body>
</html>
这是我的javascript:
$.getJSON(accountProjects, function(data) {
//Do stuff....
});
我该怎么做?
答案 0 :(得分:0)
尝试以下解决方案 -
function loadLibrary() {
alert("write below");
$.getJSON(accountProjects, function(data) {
//Do stuff....
});
}
$(document).ready(function() {
loadLibrary();
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<html>
<body>
<script type="text/javascript">loadLibrary()</script>
</body>
</html>