Home > Web Front-end > JS Tutorial > JavaScript implements select and adds option_javascript tips

JavaScript implements select and adds option_javascript tips

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-05-16 15:51:35
Original
1376 people have browsed it

JavaScript adds option to select

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>测试文件</title>
<script>
window.onload = function(){
  //创建select控件
  var _select = document.createElement("SELECT");
  
  //添加选项
  for(var i=1; i<=10; i++){
    var _option = new Option(i,i);
    _select.options.add(_option);
  }
  
  //选中值发生改变时的处理函数
  _select.onchange = function(){
    alert(_select.value); //取select控件被选中的值
  }
  
  document.body.appendChild(_select);
}
</script>
</head>

<body>
</body>
</html>
Copy after login

The above is the entire content of this article, I hope you all like it.

Related labels:
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Issues
What are JavaScript hook functions?
From 1970-01-01 08:00:00
0
0
0
What is JavaScript garbage collection?
From 1970-01-01 08:00:00
0
0
0
c++ calls javascript
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template