还有更优雅和正确的方法。不要忘记可用性。跳过冒号,这不是纸质表格!
form(name="input", action="html_form_action.asp", method="get")
key Username
input(type="text", name="user")
key Password
input(type="password", name="pswd")
input(type="submit", value="Submit")
对于表单渲染,我使用的是 mixins。它使我的代码可重用且灵活。看这里:
mixin text(name, value, title)
key=title
input(type="text" name=name value=value)
mixin password(name, value, title)
key=title
input(type="password" name=name value=value)
mixin submit(name, value)
input(type="submit" name=name value=value)
form(name="input", action="html_form_action.asp", method="post")
mixin text('user', null, 'User')
mixin password('pswd', null, 'Password')
mixin submit('do', 'Login')