我在我的网页上使用selectize.js进行多项选择。 HTML代码段:
<select class="form-control" id="select_dd" multiple="multiple">
<option value="TEXT_TO_DISPLAY">
DECRIPTION
</option>
</select>
但是当我选择项目时,选择输入框中显示的文字是DESCRIPTION。我如何显示&#34;值&#34;属性而不是&#34;文本&#34;属性。
非常感谢
答案 0 :(得分:0)
一种方法是使用render
选项:这样做的好处是您可以选择文本和所选文本:
$('#select_dd').selectize({
render: {
option: function(item, escape) {
return '<div>' + item.text + ' </div>';
},
item: function(item, escape) {
return '<div>' + item.value + ' whatever </div>';
}
}
});
<!DOCTYPE html>
<html>
<head>
<title>Page Title</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
<link rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/selectize.js/0.12.4/css/selectize.bootstrap3.css" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/selectize.js/0.12.4/js/standalone/selectize.min.js"></script>
</head>
<body>
<select class="form-control" id="select_dd" multiple="multiple">
<option value="TEXT_TO_DISPLAY_1">DECRIPTION 1</option>
<option value="TEXT_TO_DISPLAY_2">DECRIPTION 2</option>
<option value="TEXT_TO_DISPLAY_3">DECRIPTION 3</option>
</select>
</body>
</html>