使用此插件https://github.com/brianreavis/selectize.js进行此下拉列表。
在加载时,必须检查检测到的国家/地区。如果检测到国家" AU",则必须触发id =" AU"的选项。
尽我所能触发..但我的脚本不能用于自动触发。它必须触发" selectize-dropdown-content" div容器触发。
HTML
<select name="select" id="select" >
<option id="EN" value="global.html">Global</option>
<option id="AU" value="australia.html">Australia</option>
<option id="ID" value="Indonesia.html">Indonesia</option>
</select>
在浏览器中,它呈现如下格式:
<select name="select" id="select" class="custom-select elem-width selectized" placeholder="Select Country" data-validation="required" tabindex="-1" style="display: none;">
<option value="others.html" selected="selected"></option>
</select>
<div class="selectize-control custom-select elem-width single">
<div class="selectize-input items full has-options has-items">
<div data-value="others.html" class="item">Others</div>
<input type="text" autocomplete="off" tabindex="" style="width: 106px; opacity: 0; display: inline-block;">
</div>
<div class="selectize-dropdown custom-select elem-width single" style="display: none; visibility: visible; width: 235px; top: 40px; left: 0px;">
<div class="selectize-dropdown-content">
<div data-value="others.html" data-selectable="" class="option selected">Others</div>
<div data-value="US.html" data-selectable="" class="option">United States (US)</div>
<div data-value="kr.html" data-selectable="" class="option">Korea</div>
</div>
</div>
</div>
JS:
function getCode () {
var now = new Date().getTime();
var randomNumber = Math.floor((Math.random() * 100) + 1);
var uniqueNumber = now + 'a' + randomNumber;
$.getScript("getCountryCode.js?" + uniqueNumber, function(data, textStatus, jqxhr) {
if (country){
var code = country;
console.log("countryCode:" + countryCode);
$('.selectize-dropdown-content div').trigger('change');
}
});
}