我想使用Select2庫來顯示類別列表。我目前有一個正常工作的<select>
。無法調用方法'select2'null
我在我的html中添加了jquery,樣式表,.js文件和函數。
<link href="/select2/select2.css" rel="stylesheet"/>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js" ></script>
<script src="/select2/select2.js"></script>
<script>
$(document).ready(function() { $("#listCategorie").select2(); });
</script>
然而,選擇仍然正常顯示,我得到以下錯誤控制檯:
遺漏的類型錯誤:無法調用空
的方法「選擇2」這是選擇我有:
<select id="listCategorie">
<option value="0"></option>
....
</select>
'$(「#listCategorie」)'不正確,返回null。 – Archer
選擇ID設置爲listCategorie,它存在於我的HTML中。它應該能夠找到它,因爲在加載DOM時調用該函數。 – oliboon
對不起,但這就是錯誤的含義。你是偶然在本地運行,還是在網絡服務器上運行?如果在本地,是在本地主機上還是作爲文件運行('file://')? – Archer