如何获取多选tokenize2控件的文本? 我可以轻松获得多选的价值,但我不知道如何获取文本
插件链接: https://zellerda.github.io/Tokenize2/index.html
代码:
<select class="tokenize-demo" multiple>
<option value="1">Africa</option>
<option value="2">Americas</option>
<option value="3">Asia</option>
<option value="4">Europe</option>
<option value="5">Oceania</option>
</select>
Jquery的:
<script>
$('.tokenize-demo').tokenize2();
$('.tokenize-demo').on("tokenize:tokens:add", function (event, value) {
console.log("Value is "+value); //here i am getting selected value like 1,2,3..etc.
console.log("Text is "+?);//here i want text from options like Africa
});
</script>
答案 0 :(得分:2)
没有足够的文档,但我设法找到了解决方案。 Text
属性实际上是在事件侦听器函数的第三个参数中传递的。修改您的事件监听器,如下所示:
$('.tokenize-demo').on("tokenize:tokens:add", function (event, value, text){
console.log("Value is "+value); // To get value
console.log("Text is "+ text); // To get text
});