我已经参考了 select2 jQuery 插件提供的这个文档。 http://ivaynberg.github.io/select2/
但是当我使用此代码来限制用户一次可以选择的选项数量时:
$(document).ready(function(){
$(".select2").select2({ maximumSelectionSize: 2 });
});
这是选择标签的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>
当我尝试限制它时,我在控制台中收到此错误:
未捕获的类型错误:对象 [object Object] 没有方法“select2”
为什么?我的意思是 select2 工作正常,这意味着它的 js 文件正在加载,那么为什么我无法限制它呢?