Copy Code code as follows:
$ (function () {
Pagejs.urls = [
'/', ' Index ',
];
Pagejs.run ();
});
The functions include HTML elements. Ajax function also can is put here.
var Common = {
Init:function () {
Alert (' Common ');
}
};
Url--pages
var Index = {
Init:function () {
Common.init ();
This.test ();
This.test2 ();
alert (location.pathname);
},
Test:function () {
Alert (' Test ');
}
};
Index.test2 = function () {
Index.test ();
Alert (' Test2 ');
}
Should be remove to other JS file, and load before this file.
The functions don ' t include any HTML elements.
var Utils = {
Debug:function () {
}
};
var Pagejs = {
URLs: [],
Run:function () {
var urls = This.urls;
alert (urls.length);
if ((urls.length% 2)!= 0) {
Throw "URL error";
}
var len = URLS.LENGTH/2;
for (var i = 0; I <= len; i = i + 2) {
var pattern = new RegExp (urls[i], ' I ');
if (Pattern.test (Location.pathname)) {
Eval (urls[i + 1] + ". Init ()");
Break
}
}
}
};