访问使用javascript的玉元素

我有一个input标签的文本types。 我想访问input标签的值,每当用户input和推送到JSON。

我的玉文件看起来像,

扩展布局

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

我正在写快速访问代码,

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

我是初学者的JavaScript,节点和玉器。

使用表单将您的数据提交给服务器:

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

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

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