I have refered to this docs provided by select2 jquery plugin. http://ivaynberg.github.io/select2/
我已经提到了select2 jquery插件提供的这个文档。 http://ivaynberg.github.io/select2/
But when I use this code to limit the number of options a user can select at a time:
但是,当我使用此代码来限制用户一次可以选择的选项数量时:
$(document).ready(function(){
$(".select2").select2({ maximumSelectionSize: 2 });
});
And here is the html of select tag:
以下是select标签的html:
<select id="store-name" name="state[]" class="select2-select-00 span6" multiple size="5"
data-placeholder="Store" style="height:25px;">
<?php foreach ($this->Store->get_all_stores_names() as $row) {
//print_r($row);
echo '<option value="' . $row->name . '"> ' . $row->name . '</option>';
}
?>
</select>
When i try to limit it , I get this error in console, "Uncaught TypeError: Object [object Object] has no method 'select2' ". Why? I mean the select2 works fine which means that it's js files are being loaded,then why I am unable to limit it? Thanks
当我试图限制它时,我在控制台中收到此错误,“未捕获TypeError:对象[对象对象]没有方法'select2'”。为什么?我的意思是select2工作正常,这意味着它正在加载js文件,那么为什么我无法限制它?谢谢
1 个解决方案
#1
4
Use maximumSelectionLength like so:
像这样使用maximumSelectionLength:
$("#selectQQQ").select2({
maximumSelectionLength: 3
});
#1
4
Use maximumSelectionLength like so:
像这样使用maximumSelectionLength:
$("#selectQQQ").select2({
maximumSelectionLength: 3
});