前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >网页自动提交

网页自动提交

作者头像
叶子陪你玩
发布2021-12-01 16:41:15
1.6K0
发布2021-12-01 16:41:15
举报
文章被收录于专栏:叶子陪你玩编程

昨天的视频python模拟在线测试1

核心代码:

代码语言:javascript
复制
timer = setInterval(function() {
    // 时间到自动提交试卷
    if (count==0){
        clearInterval(timer)
        alert("时间到,已自动交卷")
    }
    count--;
    tag3.innerHTML = showNum(count % 60)
    tag2.innerHTML = showNum(parseInt(count / 60) % 60)
    tag1.innerHTML = showNum(parseInt(count / 60 / 60))
}, 1000)

静态网页(复制到本地即可运行):

myclock.html

代码语言:javascript
复制
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <link rel="stylesheet" href="../static/bootstrap/css/bootstrap.min.css">
    <link rel="stylesheet" href="../static/fontawesome/css/all.css">

</head>
<body>

<p style="font-size: 48px; color: Dodgerblue;"><i class="far fa-clock"></i> <span id="h">02</span>:<span id="m">00</span>:<span id="s">00</span></p>
<script>
    window.onload = function() {
        var tag1 = document.getElementById('h')
        var tag2 = document.getElementById('m')
        var tag3 = document.getElementById('s')
        var count = 60*120
        var timer = null //timer变量记录定时器setInterval的返回值
        timer = setInterval(function() {
            // 时间到自动提交试卷
            if (count==0){
                clearInterval(timer)
                alert("时间到,已自动交卷")
            }
            count--;
            tag3.innerHTML = showNum(count % 60)
            tag2.innerHTML = showNum(parseInt(count / 60) % 60)
            tag1.innerHTML = showNum(parseInt(count / 60 / 60))
        }, 1000)

        //封装一个处理单位数字的函数
        function showNum(num) {
            if (num < 10) {
                return '0' + num
            }
            return num
        }
    }
</script>
</body>
</html>

服务器端就需要加一个到时自动点击提交按钮,相当于人点击按钮一样。

代码语言:javascript
复制
document.getElementsByTagName('form')[0].submit();

python知识库

本文参与 腾讯云自媒体同步曝光计划,分享自微信公众号。
原始发表:2021-11-18,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 叶子陪你玩编程 微信公众号,前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档