【问题标题】:TokenInput plus jQuery UI Dialog conflictTokenInput 加 jQuery UI Dialog 冲突
【发布时间】:2012-05-04 09:32:00
【问题描述】:

更新在使用 edge jQuery 的最新 Fx/Chrome 中,这似乎不再是问题


问题:自动完成将在对话框后面,如果您移动它,对话框将移出页面。

调查

我已经检查过了

Why does jquery ui dialog mangle my jquery.tokeninput.js autocomplete?

并阅读 github 请求

但我仍然对我认为是最新的东西(来自 github jQuery TokenInput 的 TokenInput JS 和 CSS)有同样的问题。


演示和代码

  • DEMO1: 注释掉 jQuery UI 时 TokenInput 的工作原理
  • DEMO2: 我想要的工作
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jqueryui/1/jquery-ui.min.js"></script>     
<link rel="stylesheet"        href="http://ajax.googleapis.com/ajax/libs/jqueryui/1/themes/base/jquery-ui.css" type="text/css" />
<script type="text/javascript" src="jquery.tokeninput.js"></script>
<link rel="stylesheet" href="token-input-facebook.css" type="text/css" />

<button id="filterBut">FILTER</button>

<div id="dialog-form" title="Filter" style="border:1px solid black">
    <p class="validateTips">Enter text contained in the respective fields</p>

    <form>
    <fieldset>
        <label for="name">Field1</label><br/><input type="text" name="Flt1" id="Flt1" class="text ui-widget-content ui-corner-all" style="width:300px"/><br/><br/>
        <label for="email">Field2</label><br/><input type="text" name="Flt2" id="Flt2" value="" class="text ui-widget-content ui-corner-all" style="width:300px" />
    </fieldset>
    </form>
</div>
<script>
$(function() {  
   $("#Flt1, #Flt2").tokenInput([
      {id: 7, name: "Ruby"},
      {id: 11, name: "Python"},
      {id: 13, name: "JavaScript"},
      {id: 17, name: "ActionScript"},
      {id: 19, name: "Scheme"},
      {id: 23, name: "Lisp"},
      {id: 29, name: "C#"},
      {id: 31, name: "Fortran"},
      {id: 37, name: "Visual Basic"},
      {id: 41, name: "C"},
      {id: 43, name: "C++"},
      {id: 47, name: "Java"}
    ],{theme:"facebook"});

  $( "#dialog-form" ).dialog({
            autoOpen: false,
            height: 400,
            width: 460,
            modal: true
  });                        
  $( "#filterBut" ).click(function() {

  // suggestion from 
  // https://stackoverflow.com/questions/6669654/why-does-jquery-ui-dialog-mangle-my-jquery-tokeninput-js-autocomplete
    $("#dialog-form script").remove();
  // does not seem to change anything


    $( "#dialog-form" ).dialog( "open" );
  });

});
</script>         
              </div>     
            </div>
          </form>                  

【问题讨论】:

    标签: jquery-ui autocomplete


    【解决方案1】:

    这是该库的一个已知问题(github 上的问题 #94)。您可以从here 收集补丁文件来解决问题。

    【讨论】:

    • 第 94 期补丁文件修复了不显示下拉菜单的问题。但是,它会在 ui 对话框上显示一个垂直滚动条。
    【解决方案2】:

    更改 div.token-input-dropdown 的样式 en css 并将 z-index:1 替换为 z-index:1005。

    【讨论】:

    • 问题不再存在。感谢您的输入
    • 这才是真正的答案
    【解决方案3】:

    我对您的 HTML 做了一些处理,似乎设置 zindex:1005 会在对话框中显示下拉菜单。

     ],{theme:"facebook", zindex:1005});
    

    但是,如果您移动对话框,自动完成下拉菜单会停留在之前的位置。

    【讨论】:

    • 太好了 - 我要到 9 月中旬才能对此进行测试,因此可能需要一段时间才能看到您的建议是否有效
    • 我已上传代码here供您测试。
    • 谢谢 - 在 FX15 OSX 中,当我输入时,该字段会变短,并且建议是透明的。它似乎在 Chrome 也适用于 OSX
    【解决方案4】:

    这个 jQuery 代码为我解决了隐藏问题(感谢 @user2192014 和 this answer 的想法):

    $(".token-input-dropdown-facebook, .token-input-list-facebook").css("z-index","9999");
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-09-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多