【问题标题】:Ejs form action is not working with node js?Ejs 表单操作不适用于节点 js?
【发布时间】:2016-07-22 03:35:55
【问题描述】:

Ejs

 <h4 style="display: inline">You are Connected to:</h4>
          <u style="display: inline"><%= host %>:<%= port%> </u>
        </br> </br>
        <h4 style="display: inline">Output is:</h4>
        <u style="display: inline"><%= temp %> </u> </br>
      </section> </br>
        <label> Click on graph for live updated graph! </label>
      </br></br>
        <button type="submit" formaction="/" formmethod="get" style="width: 8em;">Clear</button>
      </br> </br>

节点js

app.post('/output3', function(req, res){
client.once('message', function (message) {
      var temp = message.toString();  //here you assign temp variable with needed value
      res.render( 'index', {temp:temp, host: HOST, port: PORT})
    });
});

app.get('/', function(req, res){
  res.sendFile(__dirname + '/upload2.html')
});

当我按下清除按钮时,我想进入upload2.html。但是现在,当我按下按钮时,什么都没有发生?有什么想法吗??

【问题讨论】:

    标签: javascript node.js ejs


    【解决方案1】:

    据我所知,formaction 覆盖当前表单的action,这意味着您需要一个包含按钮的&lt;form&gt; 元素:

    <form>
      <button type="submit" formaction="/" formmethod="get" style="width: 8em;">Clear</button>
    </form>
    

    (在 Chrome 中测试)

    【讨论】:

      猜你喜欢
      • 2016-03-27
      • 1970-01-01
      • 1970-01-01
      • 2016-11-29
      • 2018-10-26
      • 2016-01-25
      • 1970-01-01
      • 2020-05-21
      • 1970-01-01
      相关资源
      最近更新 更多