我使用ajax构建一个下拉列表。第一次单击下拉列表时,它将显示带有垂直滚动条的列表。第二次单击下拉列表时,滚动条消失了。如何在第一时间隐藏滚动条?
以下几行是代码段:
<select class="w3-select w3-border" name="building" id="building" onclick="loadBuildingOptionsCall(this)" onchange="">
<option value="" disabled selected>select building</option>
</select>
function loadBuildingOptionsCall(obj){
loadOptionsRequest('/loadBuildingOptions', loadBuildingOptions);}
function loadOptionsRequest(url, cFunction) {
var xhttp;
xhttp=new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
cFunction(this);
}
};
xhttp.open("GET", url, true);
xhttp.send();
}
function loadBuildingOptions(xhttp) {
var obj = JSON.parse(xhttp.responseText);
var elm=document.getElementById("building");
var optionCount=0;
for(var i=0;i<elm.childNodes.length;i++){
if(elm.childNodes[i].nodeName=='OPTION') optionCount++;
}
if(optionCount==1){
for (var key in obj)
{
document.getElementById("building").innerHTML+="<option value='2'>"+key+"</option>";
}
}}