我怎样才能选择插入选项的文本,而不仅仅是值? [英] How can I get selectize to insert the text of the option, not just the value?

查看:81
本文介绍了我怎样才能选择插入选项的文本,而不仅仅是值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用Selectize.js处理表单中的多选字段.当您从下拉列表中选择一个选项时,它会向select字段添加一个选择,但只会添加数据值.有谁知道是否有一种简便的方法来使Selectize也可以从选项中添加文本?​​

I am trying to use Selectize.js to handle a multi-select field in my form. When you select an option from the dropdown, it adds a selection to the select field , but only adds the data value. Does anyone know if there is an easy way to get Selectize to add the text from the option as well?

推荐答案

使用.getItem(value)方法.

Use the .getItem(value) method.

https://github.com/brianreavis/selectize.js/blob/master/docs/api.md#methods_options

在这里尝试: http://jsfiddle.net/pzekurvp/5/

var selectizedElement, $selectizedElement;

$selectizedElement = $('#select-state').selectize({
    onItemAdd: function (value, $item) {
        alert(this.getItem(value)[0].innerHTML);
    }
});

selectizedElement = $selectizedElement[0].selectize;

这篇关于我怎样才能选择插入选项的文本,而不仅仅是值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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