繁体   English   中英

用户单击按钮时如何在 node.js 和哈巴狗中删除上一个问题时显示新问题?

[英]How to display new question when user click button and previous question delete in node.js and pug?

我想做一个简单的测验。 当用户单击按钮时,向他显示新问题。 我不知道该怎么做。

index.js

const express = require('express')
const app = express()

app.set('view engine', 'pug')
app.use(express.urlencoded({ extended: false }))

app.get('/', (req, res) => {
    questions = ['firstQuestion', 'secondQuestion']
    for (i = 0;i<questions.length;i++) {
        res.render('index', {question: question[i]})
    }
})

app.listen(3000)

指数.pug

html(lang="en")
    head
        meta(charset="UTF-8")
        meta(http-equiv="X-UA-Compatible", content="IE=edge")
        meta(name="viewport", content="width=device-width, initial-scale=1.0")
        title Document
    body
        h1#a
        button(onclick='func()')
    script.
        function func() {
            document.getElementById("a").innerHTML = #{question}
        }

我不确定哈巴狗是如何工作的,但我有一些一般的想法给你

  1. 您可以在将 ip 映射到问题编号的服务器/数据库中保存字典。
  2. 您可以将 cookies 推送到用户客户端并将问题索引发送为 header
  3. 您可以使用实时 web sockets 例如 Socket.io

请记住,您必须将数据保存在某处(userId 到 userQuestionIndex)。这取决于您希望应用程序的安全程度。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM