当我在 bootstrap 模式中使用select2(输入)时,我无法在其中键入任何内容.就像是残障人士?在MODEL SELET2之外工作正常.

enter image description here

工作示例:http://jsfiddle.net/byJy8/1/

<!-- Modal -->
<div id="myModal" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
        <h3 id="myModalLabel">Panel</h3>
    </div>
    <div class="modal-body" style="max-height: 800px">          
      <form class="form-horizontal">
        <!-- Text input-->
        <div class="control-group">
            <label class="control-label" for="vdn_number">Numer</label>
            <div class="controls">
                <!-- seleect2 -->
                <input name="vdn_number" type="hidden" id="vdn_number"  class="input-large" required=""  />
            </div>
        </div>
      </form>    
    </div>
    <div class="modal-footer">
        <button class="btn" data-dismiss="modal" aria-hidden="true">Close</button>
        <button class="btn btn-primary">Save changes</button>
    </div>
</div>

JS

$("#vdn_number").select2({
    placeholder: "00000",
    minimumInputLength: 2,
    ajax: {
        url: "getAjaxData/",
        dataType: 'json',
        type: "POST",
        data: function (term, page) {
            return {
                q: term, // search term
                col: 'vdn'
            };
        },
        results: function (data) { // parse the results into the format expected by Select2.
            // since we are using custom formatting functions we do not need to alter remote JSON data
            return {results: data};
        }
    }
});

答案:

在这里你可以快速找到fix

and here is 'the right way': Select2 doesn't work when embedded in a bootstrap modal

推荐答案

好的,我已经把它弄好了.

变化

<div id="myModal" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-header">
        <but至n type="but至n" class="close" data-dismiss="modal" aria-hidden="true">×</but至n>
        <h3 id="myModalLabel">Panel</h3>
    </div>
    <div class="modal-body" style="max-height: 800px">

<div id="myModal" class="modal hide fade" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-header">
        <but至n type="but至n" class="close" data-dismiss="modal" aria-hidden="true">×</but至n>
        <h3 id="myModalLabel">Panel</h3>
    </div>
    <div class="modal-body" style="max-height: 800px">

(从modal中移除tabindex="-1")

Jquery相关问答推荐

如果链接包含多个关键字,jQuery 将 HTML 添加到链接

退出 jquery.each 循环后

在不同的行插入不同的值

5 秒后关闭 jQuery 弹出模式

用 jQuery/JavaScript 检测数字或字母?

如何像这样通过 $.ajax ( serialize() + extra data ) 添加数据

如何确定 jQuery 中匹配元素的元素类型?

Google Maps API v3 infowindow 关闭事件/回调?

jQuery JSON到字符串?

如果 iframe src 无法加载,则捕获错误.错误:-拒绝在框架中显示 'http://www.google.co.in/'..

如何触发href元素的点击事件

jQuery DataTables:延迟搜索直到输入 3 个字符或单击按钮

jQuery:如何从 $.ajax.error 方法中获取 HTTP 状态代码?

如何签入用户已在 Google recaptcha 中选中复选框的 js?

如何使用 javascript 擦除所有内联样式并仅保留 css 样式表中指定的样式?

在 bootstrap 弹出窗口中包含表单?

jQuery - 从元素内部 Select 元素

CORS - 如何预检httprequest?

一起使用 JQuery-Mobile/Phonegap 的正确方法?

使用 Ajax 下载并打开 PDF 文件