Rails自动对焦在文本字段标记中

时间:2018-03-27 13:59:54

标签: ruby-on-rails

我有text field tag,我想打开它上面的autofocus

在没有id:"email的情况下工作正常,但是当我添加id:"email时,autofocus无效。

<%= text_field_tag :email, params[:email], autofocus: true, class: "email", id:"email", placeholder: "#{I18n.t 'email_placeholder'}"%> 

任何想法可能有什么问题?

另外,我在这个字段中使用typeahead

<script>
var items = new Bloodhound({
    datumTokenizer: Bloodhound.tokenizers.whitespace,
    queryTokenizer: Bloodhound.tokenizers.whitespace,
    remote: {
        url: '/items/autocomplete?search=%SEARCH',
        wildcard: '%SEARCH'
    }
});
$('#email')
    .typeahead(null, {source: items})
    .on('typeahead:selected', function(e){
        e.target.form.submit();
    });
</script>

0 个答案:

没有答案