我有一个文本输入标签。每当用户输入并将其推送到json时,我都想访问input标签的值。

我的玉器档案看起来像

扩展布局

block content
  h1 todos
  #task
  <input type="text" id="task" name="task"/>
  #todos
    for todo in todos
      include todo


我正在使用Express编写访问代码,

    app.get('/', function(req,res){
        todos.push(new todo(req.bodyParser.task))
        res.render('index',{todos:todos});
});


我也是javascript,node和jade的初学者。

最佳答案

使用表格将数据提交到服务器:

block content
  h1 todos
  form(action="/todos", method="post", id="taskform")
    input(type="text", name="task")
  #todos
    for todo in todos
      include todo


在节点中,现在您可以使用task访问req.body.task

app.post('/todos', function(req,res){
   todos.push(new todo(req.body.task))
   res.render('index',{todos:todos});
});

关于javascript - 使用javascript访问 Jade 元素,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/25915208/

10-12 15:13