Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/79.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何每秒单击一个特定按钮_Javascript_Jquery_Repeat_Clicking - Fatal编程技术网

Javascript 如何每秒单击一个特定按钮

Javascript 如何每秒单击一个特定按钮,javascript,jquery,repeat,clicking,Javascript,Jquery,Repeat,Clicking,该网页的代码如下: <div id="content"> <div class="container-fluid"> Slots <p>The current jackpot is 23220!<p/> <p>You lose.</p> <form method=post action=/games/slots.php>

该网页的代码如下:

<div id="content">
    <div class="container-fluid">
        Slots
        <p>The current jackpot is 23220!<p/>
        <p>You lose.</p>
        <form method=post action=/games/slots.php>
            <input type=hidden name='hash_sub' value='MjEzOA=='>
            <input type=hidden name='act' value='spin'>
            <input type=submit value='Spin again!'>
        </form>
        <a href='slots.php'>Go Back</a>
    </div>
</div> 

我不确定我遗漏了什么,页面加载了,但按钮根本没有点击。没有控制台日志错误。

content div的选择器不正确,应该是这样的

setInterval(function solo() {
jQuery('#content').children('submit[value="Spin again!"]').click();
}, 1000);
您需要使用带有ID的
#
,而不是。As
.children()
只遍历直接子代,而As
.find()
将查找子代

使用

另外,当您使用
children('submit[value=“Spin reach!”)
时,它会查找值为
Spin reach的
submit
元素


使用jQuery(“#content”)看,我尝试添加了标签,但没有明显的区别。我再次刷新/进入页面,但加载后什么也没有发生。由于某种原因,我不知道为什么setInterval(函数solo(){jQuery('#content').find('input[type=“submit”]:nth child(3'))。click();console.log(“1”);},1000)@TonyVu为什么要使用
:第n个孩子(3)
?我使用谷歌的Chrome控制台CSS路径检查了元素,并获得了#content>div.container-fluid>center>form>input[type=“submit”]:第n个孩子(3)返回。我简化了代码。实际页面在这里。我不认为and>标记会使代码不起作用。我确认它也起作用。不过这比说div的第三个元素更具体,因此更好。
setInterval(function solo() {
jQuery('#content').children('submit[value="Spin again!"]').click();
}, 1000);
setInterval(function () {
    jQuery('#content').find('input[type=submit][value="Spin again!"]').click();
}, 1000);