如何禁用"no-results-text"?

How to disable "no-results-text"?

我想在 jQuerys Chosen 1.1.0 中禁用无结果文本。

我尝试了一些代码更改,但没有达到预期的结果。我所达到的只是我禁用了整个搜索功能或者无结果文本是 "undefined".

仅禁用像 "No results match" 这样的无结果文本的关键在哪里?

非常感谢!

根据 1.1.0 版文档,是您可以在首次调用 chosen 函数时设置的选项 示例:

$(".my_select_box").chosen(
    disable_search_threshold: 10,
    no_results_text: "Oops, nothing found!",
    width: "95%"
  );

 $(".chosen-select").chosen({no_results_text: "Oops, nothing found!"}); 

示例 使用 &nbsp 实体来禁用超过键入的任何文本

<!Doctype html>

<html class="no-js" lang="en">
<!--<![endif]-->
  <head>
<link href="https://cdnjs.cloudflare.com/ajax/libs/chosen/1.1.0/chosen.css" rel="stylesheet"/>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/chosen/1.1.0/chosen.jquery.min.js"></script>
<link href="https://cdnjs.cloudflare.com/ajax/libs/chosen/1.1.0/chosen.min.css" rel="stylesheet"/>
</head>
<html>
  <body>
    
    <select data-placeholder="Choose a Country..." class="chosen-select" style="width:350px;" tabindex="2">
            <option value=""></option>
            <option value="United States">United States</option>
            <option value="United Kingdom">United Kingdom</option>
            <option value="Afghanistan">Afghanistan</option>
            <option value="Aland Islands">Aland Islands</option>
            <option value="Albania">Albania</option>
            <option value="Algeria">Algeria</option>
    </select>    
  </body>  
  <script>
     $(".chosen-select").chosen({no_results_text: "&nbsp"});
  </script>
</html>

您还可以在加载 jquery 选择的插件及其 css:

后将此 css 添加到您的 head 标签中
<style>
      li.no-results {
       visibility:hidden;
      }
</style>

或者修改 chosen.css 的来源并将 visibility:hidden 添加到 no-results class 如果没有结果,将删除任何 message/text在搜索中

示例visibility:hidden 添加到 no-results class 以隐藏任何文本

<!Doctype html>

<html class="no-js" lang="en">
<!--<![endif]-->
  <head>
<link href="https://cdnjs.cloudflare.com/ajax/libs/chosen/1.1.0/chosen.css" rel="stylesheet"/>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/chosen/1.1.0/chosen.jquery.min.js"></script>
<link href="https://cdnjs.cloudflare.com/ajax/libs/chosen/1.1.0/chosen.min.css" rel="stylesheet"/>
    
    <style>
        li.no-results{visibility:hidden;}
    </style>
</head>
<html>
  <body>
    
    <select data-placeholder="Choose a Country..." class="chosen-select" style="width:350px;" tabindex="2">
            <option value=""></option>
            <option value="United States">United States</option>
            <option value="United Kingdom">United Kingdom</option>
            <option value="Afghanistan">Afghanistan</option>
            <option value="Aland Islands">Aland Islands</option>
       
    </select>    
  </body>  
  <script>
     $(".chosen-select").chosen({no_results_text: "This message is hidden"});
  </script>
</html>