2

我正在尝试重构我的应用程序以使用jade而不是ejs,但在设置登录表单时遇到了一些问题。

这是我在 ejs 中的原始表单:

<% if (message) { %>
<p><%= message %></p>
<% } %>

<form class="form-horizontal" action='/login' method="POST" id="loginForm">
  <fieldset>
    <div id="legend">
      <legend class="">Login</legend>
    </div>
    <div class="control-group">
      <!-- Username -->
      <label class="control-label"  for="username">Username</label>
      <div class="controls">
        <input type="text" id="username" name="username" placeholder="" class="input-xlarge">
      </div>
    </div>

    <div class="control-group">
      <!-- Password-->
      <label class="control-label" for="password">Password</label>
      <div class="controls">
        <input type="password" id="password" name="password" placeholder="" class="input-xlarge">
      </div>
    </div>

    <div class="control-group">
      <!-- session-->
      <label class="control-label" for="rememberme">Remember Me</label>
      <div class="controls">
        <input type="checkbox" name="rememberme"/>
      </div>
    </div>


    <div class="control-group">
      <!-- Button -->
      <div class="controls">
        <button class="btn btn-success">Login</button>
      </div>
    </div>
  </fieldset>
</form>

这是我的新玉形式:

extends layout

block content
    if message
        p= message
    form(class='form-horizontal',action='/login',method='POST',id='loginForm')
        fieldset
            div#legand
                legend Login
            div.control-group
                label(for='username',class='control-label') Username
                div.controls
                    input(type='text',id='username',name='username',placeholder='Username',class='input-xlarge')
            div.control-group
                label(for='password',class='control-label') Password
                div.controls
                    input(type='text',id='password',name='password',placeholder='Password',class='input-xlarge')
            div.control-group
                label(for='rememberme',class='control-label') Remember Me
                div.controls
                    input(type='checkbox',name='rememberme')
            div.control-group
                div.controls
                    input(type='submit',class='btn btn-success') Login

Codekit 抛出错误:

/Applications/CodeKit.app/Contents/Resources/engines/jade/lib/runtime.js:173
  throw err;
        ^
Error: /Users/sm/Documents/Projects/Web_Applications/App/app/views/login.jade:27
    25| 
    26| 
  > 27|   

Invalid indentation, you can use tabs or spaces but not both
    at Object.Lexer.indent (/Applications/CodeKit.app/Contents/Resources/engines/jade/lib/lexer.js:672:15)
    at Object.Lexer.next (/Applications/CodeKit.app/Contents/Resources/engines/jade/lib/lexer.js:770:15)
    at Object.Lexer.blank (/Applications/CodeKit.app/Contents/Resources/engines/jade/lib/lexer.js:179:19)
    at Object.Lexer.next (/Applications/CodeKit.app/Contents/Resources/engines/jade/lib/lexer.js:744:15)
    at Object.Lexer.blank (/Applications/CodeKit.app/Contents/Resources/engines/jade/lib/lexer.js:179:19)
    at Object.Lexer.next (/Applications/CodeKit.app/Contents/Resources/engines/jade/lib/lexer.js:744:15)
    at Object.Lexer.lookahead (/Applications/CodeKit.app/Contents/Resources/engines/jade/lib/lexer.js:106:46)
    at Object.Parser.lookahead (/Applications/CodeKit.app/Contents/Resources/engines/jade/lib/parser.js:115:23)
    at Object.Parser.peek (/Applications/CodeKit.app/Contents/Resources/engines/jade/lib/parser.js:92:17)
    at Object.Parser.tag (/Applications/CodeKit.app/Contents/Resources/engines/jade/lib/parser.js:666:30)

我怎样才能克服这个缩进错误并让这个表格工作?我只使用制表符,没有空格,所以我不明白问题是什么。

4

2 回答 2

2

这可能是由 Jade 模板中尾随空行中的空格引起的(您没有发布,但根据错误消息存在)。

于 2013-05-14T12:48:27.410 回答
1

我认为您的问题可能是您如何指定按钮。代替:

            div.control-group
                div.controls
                    input(type='submit',class='btn btn-success') Login

尝试:

            div.control-group
                div.controls
                    button(type='submit',class='btn btn-success') Login

于 2014-11-21T20:26:45.183 回答