如何解决如何避免 'Uncaught ReferenceError: ?未定义'?
我在每个页面的底部都有一个脚本 (config.js)。但是,该脚本包含并非在每个页面上都使用的代码。控制台将未使用或未声明的变量返回为未定义。
class Solution:
def exist(self,board: List[List[str]],word: str) -> bool:
def dfs(x=0,y=0,found=0,seen = set()):
if found == len(word):
return True
elif x < len(board) and y < len(board[0]) and board[x][y] == word[found]:
if x > 0 and (x,y) not in seen:
seen.add((x,y))
dfs(x-1,y,found+1,seen.copy())
seen.remove((x,y))
if x < len(board) and (x,y))
dfs(x+1,y))
if y > 0 and (x,y))
dfs(x,y-1,y))
if y < len(board[0]) and (x,y+1,y))
return dfs()
我该如何解决这个问题?
解决方法
在尝试使用之前,您需要检查 redirect
元素是否存在。
function redirectURL() {
if (typeof redirect == 'undefined') {
return;
}
if (currentURL.indexOf('dogs.html') > -1) {
redirect.innerHTML = `<a href="/pets/cats.html">Cats</a>`;
} else {
redirect.innerHTML = `<a href="/pets/dogs.html">Dogs</a>`;
}
}
这将允许函数在没有定义 redirect
的页面上正常工作。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。