php 如何让我的用户在30秒后自动进入下一步?

7kqas0il  于 2023-09-29  发布在  PHP
关注(0)|答案(1)|浏览(86)

我有一个代码,使我的用户点击(点击这里继续)按钮后转到下一页,我想让我的用户30秒后自动进入下一步

<div class="col-md-<?= $col_num ?>">
        <?= $this->Flash->render() ?>

        <?= $this->Form->create(null, ['id' => '']); ?>
        <?= $this->Form->hidden('action', ['value' => 'continue']); ?>
        <?= $this->Form->hidden('page', ['value' => $page + 1]); ?>
        <?= $this->Form->button(__('Click here to continue'), ['class' => 'btn btn-primary',]); ?>
        <?= $this->Form->end() ?>
    </div>
hgb9j2n6

hgb9j2n61#

您可以使用JavaScript模拟30秒后单击按钮。首先,为按钮添加唯一标识符

<?= $this->Form->button(__('Click here to continue'), ['class' => 'btn btn-primary', 'id' => 'auto_click']); ?>

然后将以下JS添加到HTML内容的结束body标记附近

<script>
    setTimeout(function() {
        document.getElementById('auto_click').click();
    }, 30000);
</script>

JS Fiddle

相关问题