Javascript select2不是一个函数
我有这个htmlJavascript select2不是一个函数,javascript,jquery,select2,Javascript,Jquery,Select2,我有这个html <div class="input-box"> <select id="billing:country_id" class="validate-select" name="billing[country_id]" title="Country"> <option value=""> </option> </select> </div>
<div class="input-box">
<select id="billing:country_id" class="validate-select" name="billing[country_id]" title="Country">
<option value=""> </option>
</select>
</div>
<div class="input-box">
<select id="billing:region_id" class="validate-select" name="billing[region_id]" title="State">
<option value=""> </option>
</select>
</div>
<script type="text/javascript">
jQuery("#billing\\:country_id").select2({
placeholder: "Select a Country"
});
jQuery("#billing\\:region_id").select2({
placeholder: "Select State"
});
jQuery("#billing\\:country_id").change(function(){
jQuery("#billing\\:region_id").select2('destroy');
jQuery("#billing\\:region_id").select2({
placeholder: "Select a State"
});
});
</script>
但当我尝试更改国家/地区下拉列表时,我出现了以下错误:
TypeError:jQuery…select2不是函数
jQuerybilling \:区域\ u id.选择2'destroy' 除了整个函数应该封装在jquery中之外,我没有看到任何错误。为了演示,我只添加了3个选项 $function{ $billing\\:国家/地区识别码。选择2{ 占位符:选择一个国家/地区 }; $billing\\:区域\u id.选择2{ 占位符:选择状态 }; $billing\\:国家/地区id.changefunction{ $billing\\:区域\标识。选择2“销毁”; $billing\\:区域\u id.选择2{ 占位符:选择一个状态 }; }; }; 选择1 选择2 选择3 选择1 选择2 选择3
未包含select2.js?已包含,国家/地区选择正常,但当存在状态下拉列表时,我看到此错误确保在代码之前导入select2.js。和remove\\from billing\\:region\u id&billing\\:country\u id如果我删除此项将不起作用,则无法选择id首先使用jquery函数封装整个代码。e、 g$函数{//您剩余的代码写在这里。}并告诉我状态。您没有在id中使用:。使用它们来排除导致错误的不是选择器或css转义。。。所以我用onload而不是$ready测试了它: