【发布时间】:2014-09-25 22:42:48
【问题描述】:
我有一个文本字段
= text_field_tag('search_text_1', params[:search_text],
options = {:type => 'search'} )
生成
<input id="search_text" name="search_text_1" type="search">
我想添加 HTML5 自动对焦,如
= text_field_tag('search_text_1', params[:search_text],
options = {:type => 'search', :autofocus => true} )
这会生成
<input autofocus="autofocus" id="search_text" name="search_text_1" type="search">
这确实有效,但我怎样才能获得autofocus 的实际 HTML 输出,如 HTML 规范所示,即
<input autofocus id="search_text" name="search_text_1" type="search" autofocus>
# Not sure where it goes or if that matters
使用
options = {:type => 'search', :autofocus }
给予
.../_search.html.haml:2: syntax error, unexpected '}', expecting =>
...:type => 'search', :autofocus } )
正如https://developer.mozilla.org/en-US/docs/Web/HTML/Element/Input 的 HTML5 规范所说,“这是一个布尔值”
【问题讨论】:
-
但我猜你可以use haml...
-
无论如何,it's valid.
标签: ruby-on-rails ruby html autofocus