gpt4 book ai didi

javascript - 我的代码中的 Var 不起作用

转载 作者:行者123 更新时间:2023-11-28 19:09:29 26 4
gpt4 key购买 nike

我的代码中的“Var”不起作用。它总是显示'hasclass = 0 and body has class',但应该hasclass = yes and body has class

setInterval(function() {
if($('.webMessengerMessageGroup').length>0) {
if(hasclass === 'dooainn') {
console.log('hasclass = yes and body has class');
} else {
var hasclass = 'dooainn';
console.log('hasclass = 0 and body has class');
$('._38 p').click(function () {
var message_text = $(this).text();
console.log(message_text);
});
}
} else {
console.log('body has not class');
}
},2000);

最佳答案

var hasclass 未在 if 范围内定义。如果将 var 移到函数之外,如下所示,它应该可以工作。

var hasclass = '';
setInterval(function() {
if($('.webMessengerMessageGroup').length>0) {
if(hasclass === 'dooainn') {
console.log('hasclass = yes and body has class');
} else {
hasclass = 'dooainn';
console.log('hasclass = 0 and body has class');
$('._38 p').click(function () {
var message_text = $(this).text();
console.log(message_text);
});
}
} else {
console.log('body has not class');
}
},2000);

关于javascript - 我的代码中的 Var 不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31007891/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com