javascript - 在下拉列表的第一行添加自定义文本

标签 javascript jquery

 if (this.is_multiple) {
            this.container.html('<ul class="chosen-choices"><li class="search-field"><input type="text" value="' + this.default_text + '" class="default" autocomplete="off" placeholder="choose your&nbsp;' + this.default_text + '" style="width:25px;" /></li></ul><div class="chosen-drop"><ul class="chosen-results"><li class="choose"></li></ul></div>');
        } else {
            this.container.html('<a class="chosen-single chosen-default" tabindex="-1"><span>' + this.default_text + '</span><div><b></b></div></a><div class="chosen-drop"><div class="chosen-search"><input type="text" autocomplete="off" /></div><ul class="chosen-results"></ul></div>');
        }
        this.form_field_jq.hide().after(this.container);
        this.dropdown = this.container.find('div.chosen-drop').first();
        this.search_field = this.container.find('input').first();



        this.search_results = this.container.find('ul.chosen-results').first();

        this.search_field_scale();
        this.search_no_results = this.container.find('li.no-results').first();
        if (this.is_multiple) {
            this.search_choices = this.container.find('ul.chosen-choices').first();
            this.search_container = this.container.find('li.search-field').first();
        } else {
            this.search_container = this.container.find('div.chosen-search').first();
            this.selected_item = this.container.find('.chosen-single').first();
        }

我想在下拉列表的第一行中添加自定义文本。我如何添加这个请给我建议。

提前致谢。

最佳答案

您可以像这样使用 jquery。

$(function(){
var content='Choose your emotion';
$("<li disabled>"+content+"</li>").prependTo("ul.chosen-results");
});

关于javascript - 在下拉列表的第一行添加自定义文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45167033/

相关文章:

javascript - 动态为每个元素创建新的唯一 ID

javascript - 如何通过单击表格中的名称来突出显示选定的 map 区域?

javascript - 检查对象文字数组中的重复值并从中创建一个新对象

javascript - 具有绑定(bind)值的数组过滤器

javascript - 有没有办法制作一个动态放置的半透明div "holes"

javascript - 用 jQuery 对象替换

android - 在 jQuery Mobile 中完全下载后如何在 ListView 中显示图像?

javascript - 使用 jQuery 将链接更改为加载时的 anchor 链接

jquery - 使用 jQuery 创建的 Div 不显示在屏幕上

jquery - 禁用悬停在特定的单元格上