如何将标题属性添加到选择的选项标签?

问题描述:

我正在使用选择的插件",并且不确定如何向选择列表的选项标签添加属性.

I'm using "Chosen plugin" and not sure how to add an attribute to the option tags of the select list.

我已经在准备好文档的情况下使用jQuery进行了尝试,但是没有运气.

I have tried this using jQuery on document ready but no luck.

您需要将Chosen.Jquery.js修改为以下内容才能使其正常工作

you need to modify the Chosen.Jquery.js to the following to make it work

使用选择的1.0版本

第62行添加此行代码

this.parsed.push({
        array_index: this.parsed.length,
        options_index: this.options_index,
        value: option.value,
        text: option.text,
        html: option.innerHTML,
    title: option.title, // this is Line 62 add this line
        selected: option.selected,
        disabled: group_disabled === true ? group_disabled : option.disabled,
        group_array_index: group_position,
        classes: option.className,
        style: option.style.cssText
      });

修改第255行

return "<li title=\"" + option.title +"\"  class=\"" + (classes.join(' ')) + "\"" + style + " data-option-array-index=\"" + option.array_index + "\">" + option.search_text + "</li>";