使用 ejs 视图助手为字段添加属性
Adding attributes for fields using ejs view helpers
我使用的是ejs模板渲染
<%- input_field_tag('inputFld', 5) %>
此代码将输入字段生成为
<input id="inputFld" value="" type="5" name="inputFld">
现在我想要 id
和 name
属性不同
IE。 id="inputFldID"
和 name="inputFldName"
我也想添加 class
属性。
我该如何实现?
您可能正在寻找 text_field_tag
,因为 type="5"
没有多大意义。
您可以将对象作为第三个参数传递给 text_field_tag
以及您要设置的属性。
<%- text_field_tag('inputFld', '5', {id: 'inputFldId', Class: 'some_class'}) %>
我使用的是ejs模板渲染
<%- input_field_tag('inputFld', 5) %>
此代码将输入字段生成为
<input id="inputFld" value="" type="5" name="inputFld">
现在我想要 id
和 name
属性不同
IE。 id="inputFldID"
和 name="inputFldName"
我也想添加 class
属性。
我该如何实现?
您可能正在寻找 text_field_tag
,因为 type="5"
没有多大意义。
您可以将对象作为第三个参数传递给 text_field_tag
以及您要设置的属性。
<%- text_field_tag('inputFld', '5', {id: 'inputFldId', Class: 'some_class'}) %>