<!DOCTYPE html>
<html>

<head>
<meta charset="UTF-8">
<title></title>
<script>
//创建select元素
function createSelect(){
var ele = document.createElement('select');
for(var i=0;i<10;i++){
var op = new Option('NewElment'+i,i);
ele.options[i] = op;
}
ele.size = 1;
ele.id = 'city';
document.getElementById('test').appendChild(ele);
}

//删除元素
function eleremove(){
var city = document.getElementById('city');
if(city.options.length > 0){
//city.remove(city.options.length -1);
city.options[city.options.length -1] = null;
}
}

//清空元素
function clearAll(){
var city = document.getElementById('city');
if(city.options.length > 0){
city.options.length = 0;
}
}

</script>
</head>

<body >clearAll</button>
<hr />
</body>

</html>

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-10-03
  • 2021-10-16
  • 2022-02-18
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-11-30
  • 2022-12-23
相关资源
相似解决方案