How can I get selectize to insert the text of the

2019-06-28 03:55发布

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?

1条回答
Juvenile、少年°
2楼-- · 2019-06-28 04:52

Use the .getItem(value) method.

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

Try here: 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;
查看更多
登录 后发表回答