当“checkbox”类中的“ariaChecked”为“true”时,我尝试单击按钮。
这是我的第一个项目,我不知道哪里出了问题。
这是我的逻辑
setInterval(function() {
var xyz = document.getElementsByClassName("checkbox");
if(xyz[0].ariaChecked == "true")
{
clearInterval(interval);
$('.button')[0].click();
}
},1000);
答案 0 :(得分:2)
您不需要 [0]
索引,因为 jQuery 选择了带有 $('.button')
的单个元素。 Vanilla JS 返回一个数组,但由于您使用的是 jQuery,请像这样删除 [0]
索引:
$('.button').click();
<!DOCTYPE html>
<html>
<head>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
</head>
<body>
<button class="button" onclick="myFunction()">Click</button>
</body>
<script>
function myFunction() {
alert('hello');
}
</script>
</html>