簡體   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