繁体   English   中英

使用javascript访问玉元素

[英]access jade element using javascript

我有一个文本输入标签。 每当用户输入并将其推送到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

在node中,现在您可以使用req.body.task来访问task

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

暂无
暂无

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

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