我需要一些关于for for循环的帮助..我的代码应该在这些特定的URL上运行但它似乎跳过循环并应用于所有页面。感谢
$(document).ready(function () {
if (isValidUrl()) {
displayBoot();
setupBootEvents();
}
});
function isValidUrl() {
var isValid = false,
validUrls = [
"/sport/btts-match-result",
"/sport/double-delight",
"/sport/recently-paid-out",
"/promotions",
"/promotions/Sports",
"/lotto",
"/virtual",
"/bingo"
];
for (var i in validUrls) {
var currentUrl = window.location.pathname + window.location.search;
if (currentUrl == validUrls[i]) {
isValid = true;
}
}
//return isValid;
return true;
}
function displayBoot() {...
function setupBootEvents() {...
答案 0 :(得分:2)
稍微修改你的功能
function isValidUrl() {
validUrls = [
"/sport/btts-match-result",
"/sport/double-delight",
"/sport/recently-paid-out",
"/promotions",
"/promotions/Sports",
"/lotto",
"/virtual",
"/bingo"
];
for (var i in validUrls) {
var currentUrl = window.location.pathname + window.location.search;
if (currentUrl == validUrls[i]) {
return true;
}
}
return false;
}