【问题标题】:Get an html attribute in node.js在 node.js 中获取一个 html 属性
【发布时间】:2016-11-25 12:39:06
【问题描述】:

假设我有一个类似的按钮

<form action="/action1" method ="post">
<button type="submit" id="button1"> Click Me </button>
</form>

我想获取存储在属性中的值(在本例中为“id”)并执行类似的操作

app.post('/action1', function (req, res) {
var buttonId = req.id // this is the part I dont understand
});

我将如何填写该行

var buttonId = 

谢谢

【问题讨论】:

    标签: node.js


    【解决方案1】:

    发布的数据不包含id 属性。您可以设置name 和/或value 属性,它们将成为POST 请求的一部分。例如

    <button type="submit" name="button1">Click Me</button>
    

    要在此处快速查看发布的数据:Express js form data

    【讨论】:

    • 如果我打印出我的 req.body.name 它是未定义的
    • name(button1)的content是body中的key。请登录 req.body 进行检查。
    猜你喜欢
    • 2019-08-18
    • 1970-01-01
    • 2022-11-18
    • 1970-01-01
    • 2021-05-13
    • 2013-10-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多