我有一个html文件,我需要从服务器加载一些项目,为此我在js文件中使用了一个函数。现在,我可以在js文件中使用该函数,而不是在HTML文件的标记中包含该代码,并且可以通过HTML中的任何标记(只要页面加载)上的onload属性来调用它。如何在html中使用onload事件来调用js文件中的函数
我的HTML页面:
$.getScript(path + "js/jsfile.js");
data-role="button" οnclick="currentPage.back();">Back
只要这个页面被加载时,我需要的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()函数工作正常。
2015-05-04
Srujana
+0
你确定所有方法一般工作吗? –