我如何获取多选 tokenize2 控件的文本
how do i get text of multiselect tokenize2 control
如何获取 multiselect tokenize2 控件的文本?
我可以轻松获取 multi select 的值,但我不知道如何获取文本
插件 Link : 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>
没有足够的文档,但我设法找到了解决方案。 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
});
如何获取 multiselect tokenize2 控件的文本? 我可以轻松获取 multi select 的值,但我不知道如何获取文本
插件 Link : 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>
没有足够的文档,但我设法找到了解决方案。 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
});