我在用html写这段代码时遇到了问题。因为div已经有了一个form-group类,所以我不知道如何在它的内联中添加一个类exeption。
|<% if (!success) { %>
div.form-group(class!='<%- errfor.name ? "has-error" : "" %>')
label Your Name:
input.form-control(type='text', name='name', value!='<%= name %>')也许它可以作为额外的if条件添加?完整的验证表单如下所示:
script(type='text/template', id='tmpl-contact')
form
div.alerts
|<% _.each(errors, function(err) { %>
div.alert.alert-danger.alert-dismissable
button.close(type='button', data-dismiss='alert') ×
|<%- err %>
|<% }); %>
|<% if (success) { %>
div.alert.alert-info.alert-dismissable
button.close(type='button', data-dismiss='alert') ×
| We have received your message. Thank you.
|<% } %>
|<% if (!success) { %>
div.form-group(class!='<%- errfor.name ? "has-error" : "" %>')
label Your Name:
input.form-control(type='text', name='name', value!='<%= name %>')
span.help-block <%- errfor.name %>
div.form-group(class!='<%- errfor.email ? "has-error" : "" %>')
label Your Email:
input.form-control(type='text', name='email', value!='<%= email %>')
span.help-block <%- errfor.email %>
div.form-group(class!='<%- errfor.message ? "has-error" : "" %>')
label Message:
textarea.form-control(name='message', rows='5') <%= message %>
span.help-block <%- errfor.message %>
div.form-group
button.btn.btn-primary.btn-contact(type='button') Send Message
|<% } %>该应用程序在具有Backbone的Node上运行。感谢您的帮助,谢谢。
发布于 2017-01-31 07:24:50
在:
div.form-group(class!='<%- errfor.name ? "has-error" : "" %>')颠倒双引号和单引号:
div.form-group(class!="<%- errfor.name ? 'has-error' : '' %>")则html的值将是:
<div class="form-group <%- errfor.name ? 'has-error' : '' %>">并将呈现给(如果errfor.name为真):
<div class="form-group has-error">
因为您已经在多个地方使用了这个类,所以只需使用一个变量
script(type='text/template', id='tmpl-contact')
form
- var classError = "<%- errfor.name ? 'has-error' : '' %>"
div.alerts
|<% _.each(errors, function(err) { %>
div.alert.alert-danger.alert-dismissable
button.close(type='button', data-dismiss='alert') ×
|<%- err %>
|<% }); %>
|<% if (success) { %>
div.alert.alert-info.alert-dismissable
button.close(type='button', data-dismiss='alert') ×
| We have received your message. Thank you.
|<% } %>
|<% if (!success) { %>
div.form-group(class!=classError)
label Your Name:
input.form-control(type='text', name='name', value!='<%= name %>')
span.help-block <%- errfor.name %>
div.form-group(class!=classError)
label Your Email:
input.form-control(type='text', name='email', value!='<%= email %>')
span.help-block <%- errfor.email %>
div.form-group(class!=classError)
label Message:
textarea.form-control(name='message', rows='5') <%= message %>
span.help-block <%- errfor.message %>
div.form-group
button.btn.btn-primary.btn-contact(type='button') Send Message
|<% } %>https://stackoverflow.com/questions/41946135
复制相似问题