无法将焦点放在Twitter Bootstrap的Typeahead的输入上 [英] Unable to set focus on an input of Twitter Bootstrap's Typeahead

查看:47
本文介绍了无法将焦点放在Twitter Bootstrap的Typeahead的输入上的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我删除这些属性时:

data-source="<?=str_replace('"', '&quot;', json_encode($equipment, JSON_HEX_TAG | JSON_HEX_APOS)); ?>" data-items="4" data-provide="typeahead"

我能够执行此操作:

$(document).ready(function() {
    $('.first').focus();
});

这是我对此的HTML标记:

This is my HTML markup for this:

<div class="itemx">
    <input type="text" class="input-large first" autocomplete="off" placeholder="Equipment Name/Label" name="equip[]" data-source="<?=str_replace('"', '&quot;', json_encode($equipment, JSON_HEX_TAG | JSON_HEX_APOS)); ?>" data-items="4" data-provide="typeahead" />
    <input type="text" class="input-large second" placeholder="Quantity" name="quant[]" />
</div>

注意:提前输入效果很好,这没错:

NOTE: Typeahead works well an this it's nothing wrong with this:

data-source="<?=str_replace('"', '&quot;', json_encode($equipment, JSON_HEX_TAG | JSON_HEX_APOS)); ?>"

推荐答案

typeahead具有它自己的focus方法版本.避免焦点事件的默认行为,因此唯一的方法是保留预先输入的引用.

typeahead has it's own version of focus method. Default behaviour is prevented of focus event so the only way is to keep typeahead reference.

var typeaheadReference = $('.typeahead').typeahead({ ... };

然后您只需调用 typeaheadReference.focus();

这篇关于无法将焦点放在Twitter Bootstrap的Typeahead的输入上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆