如何将HTML5自动焦点添加到rails表单? [英] How to add HTML5 auto focus to a rails form?
本文介绍了如何将HTML5自动焦点添加到rails表单?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个文本字段
= text_field_tag('search_text_1', params[:search_text],
options = {:type => 'search'} )
生成
<input id="search_text" name="search_text_1" type="search">
我想添加HTML5自动对焦,如
that I want to add HTML5 autofocus to, as in
= 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">
确实有效,但我如何才能获得<$ c $的实际HTML输出c>自动对焦与HTML规范一样,即
which does actually work, but how I can I get the actual HTML output for the autofocus
to be as the HTML spec shows, i.e.
<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 说,这是一个布尔
推荐答案
我最终选择了
= text_field_tag('search_text_1',
params[:search_text],
options = {:type => 'search', :autofocus => true })
并接受 autofocus ='的输出自动对焦'
这篇关于如何将HTML5自动焦点添加到rails表单?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文