我想知道如何使用路由为多个页面执行相同的代码?这是我正在使用的示例:
var route = {
_routes: {}, // The routes will be stored here
add: function(url, action) {
this._routes[url] = action;
},
run: function() {
jQuery.each(this._routes, function(pattern) {
if (location.href.match(pattern)) {
// "this" points to the function to be executed
this();
}
});
}
}
route.add(['002.html','003.html', function() {//This is not working it only work with one string
alert('Hello there!');
});
route.add('products.html','services.html', function() {//This is not working it only work with one string
alert("this won't be executed :(");
});
route.run();