English 中文(简体)
以 javascript 定义对象
原标题:Define object in javascript

我写了一些3号的脚本 上面写着快和玉...

在索引.jadei 上有一个 3 字段并提交按钮 :

!!! 5
html
  head
    title Test
  body
    form(name= form1 , method= post , action=  )
      label(for= 1 )
      input#1(type= text , name= 1 )
      label(for= 2 )
      input#2(type= text , name= 2 )
      label(for= 3 )
      input#3(type= text , name= 3 )
      input(name= submit , type= button , value= submit ) 
    span #{result}

在服务器上(js code- node.js) 我有这个代码:

var express = require( express );
        app = express.createServer();

app.configure(function(){
    app.set( views , __dirname +  /views );
    app.set( view engine ,  jade );
    app.use(express.bodyParser());
    app.use(express.methodOverride());
    app.use(app.router);
    app.use(express.static(__dirname +  /public ));
});
app.use(express.bodyParser());
    app.get( / , function(req, res){
     res.render( index );
    });


    app.post( / , function(req, res){
      var i = req.param( 1 , null);
      var j = req.param( 2 , null);
      var k = req.param( 3 , null);
      var r = i+j+k;
      res.render( index , {result:r});

    });
app.listen(3010);

但每次我通过节点 AP.js 启动 js 文件时, 我都会收到关于对象没有定义的信息, 以及玉子文件中的一些错误 :

如何定义 ap.js 文件中的对象?

错误 :

ReferenceError: C:UsersPCglowing-frost-5319/views/index.jade:14
    12.        input#3(type= text , name= 3 )
 
    13.        input(name= submit , type= button , value= submit ) 
 
    14.      #{result} 

result is not defined
    at Object.<anonymous> (eval at <anonym... etc.

有人能告诉我如何定义对象结果以及如何在索引.jade页面上显示吗?

最佳回答

我认为您需要在 get 路线上的转换方法的第二个参数中传递结果(正如您已经在 posit 路线上所做的那样)。

尝试此 :

app.get( / , function(req, res){
    res.render( index , {result:   });
});

这将使您视图中的 结果 变量可用( 在此示例中带有空字符串值 ) 。

问题回答

暂无回答




相关问题
selected text in iframe

How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.

How to fire event handlers on the link using javascript

I would like to click a link in my page using javascript. I would like to Fire event handlers on the link without navigating. How can this be done? This has to work both in firefox and Internet ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Clipboard access using Javascript - sans Flash?

Is there a reliable way to access the client machine s clipboard using Javascript? I continue to run into permissions issues when attempting to do this. How does Google Docs do this? Do they use ...

javascript debugging question

I have a large javascript which I didn t write but I need to use it and I m slowely going trough it trying to figure out what does it do and how, I m using alert to print out what it does but now I ...

Parsing date like twitter

I ve made a little forum and I want parse the date on newest posts like twitter, you know "posted 40 minutes ago ","posted 1 hour ago"... What s the best way ? Thanx.

热门标签