我有一个html文件,我需要从服务器加载一些项目,为此我在js文件中使用了一个函数。现在,我可以在js文件中使用该函数,而不是在HTML文件的标记中包含该代码,并且可以通过HTML中的任何标记(只要页面加载)上的onload属性来调用它。如何在html中使用onload事件来调用js文件中的函数
我的HTML页面:
<script>
$.getScript(path + "js/jsfile.js");
</script>
<link rel="stylesheet" href="jqueryMobile/jquery.mobile-1.4.5.min.css">
<script src="jqueryMobile/jquery-1.11.2.min.js"></script>
<script src="jqueryMobile/jquery.mobile-1.4.5.min.js"></script>
<header data-role="header">
<a href="#" class="ui-btn ui-icon-back ui-btn-icon-left"
data-role="button" onclick="currentPage.back();">Back</a>
<!--some header tags were here-->
</header>
<div data-role="content" style="padding: 15px" >
<!--some button tags were here-->
</div>
只要这个页面被加载时,我需要的getColor()函数来执行,得到的结果取到HTML页面。
我jsfile.js页:
currentPage = {};
currentPage.init = function() {
WL.Logger.debug("listofenvironments :: init");
};
currentPage.back = function(){
WL.Logger.debug("Login :: back");
pagesHistory.push(path + "pages/otherpage.html");
$("#pagePort").load(path + "pages/" + "otherpage.html");
};
function getColor(){
//some coding goes on here....
}
我已经用在我的HTML页面中的标签的onload事件试过,但它不工作。而currentPage.back()函数工作正常。
你确定所有方法一般工作吗? – reporter