所选插件的占位符文本为单选不工作 [英] placeholder text for chosen plugin for single select not working

查看:120
本文介绍了所选插件的占位符文本为单选不工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有在我的代码中实现单选的插件。我想为搜索框添加占位符文本,但我不能。我已尝试以下操作:

I have the chosen plugin for single select implemented in my code. I am trying to add the Placeholder text for the search boxes but I am not able to. I have tried the following things:

<select id="search_pi" name="search_pi" type="text" class="chosen-select"
        style="width:450px;" onchange="this.form.submit()" >

  <option value="">Search Project/Initiative...</option>
  <?php
    include "../includes/search_dropdown.php";
    foreach($proj_ini_Array as $qa){
      echo "<option value = \"$qa\">$qa</option>";
    }
  ?>

JS

<script>
  $(document).ready(function() {
    $('.chosen-select').chosen({
      placeholder_text_single: "Select an option",
      no_results_text: "Oops, nothing found!"
    });  
  });
</script>

在选择字段中,我也尝试使用 data-placeholder =Select一个选项,但这也没有帮助。

In the select field, I also tried using data-placeholder="Select an option" but that does not help too. Can someone please let me know what am I missing?

提前感谢。

推荐答案

好的。我找到了答案。我们需要将第一个选项设为空白,以便为单一选择搜索框激活占位符文本。

Okay. I found out the answer. We need to have the first option as blank for the placeholder text to be activated for Single select search box.

<select id="search_pi" name="search_pi" type="text" class="chosen-select" style="width:450px;" onchange="this.form.submit()" >

  <option> </option>
  <?php
    include "../includes/search_dropdown.php";
    foreach($proj_ini_Array as $qa){
      echo "<option value = \"$qa\">$qa</option>";
    }
  ?>

在上述情况下,占位符文本将默认为选择一个选项。

In the above case, placeholder text will default to "Select an option".

对于单个搜索选择框的自定义占位符文本,您可以按如下所示编辑js文件,并将第一个选项留空以显示占位符文本:

For a customized placeholder-text for a single search select box you can edit your js file as below and have the first option blank for the placeholder text to be displayed:

<script>
  $(document).ready(function() {
    $('.chosen-select').chosen({
      placeholder_text_single: "Select Project/Initiative...",
      no_results_text: "Oops, nothing found!"
    });  
  });
</script>

这篇关于所选插件的占位符文本为单选不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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