<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta http-equiv="X-UA-Compatible" content="ie=edge"> <title>事件类型(onchange)</title> <!-- Code n.onchange = a; a execute code value change element n; The expansion of knowledge: a.options: return all <option> a an array element. a.selectIndex: sets or returns the index number of drop-down list in a selected option -> < Script > the window.onload = function () { // page loading function is executed after the completion var A = document.getElementById ( " SEL " ); // Get dropdown a.onchange = function () { // dropdown function executed when a change list // var Val = this.value; // can get value for each option in the drop-down list in this way var Val = a.options [a.selectedIndex] .Value; // can also be used in this method to get the drop-down list value of each option document.body.style.background = Val; //Body to set the background color, the color value is drop-down box option } } </script> </head> <body> <span>请选择页面颜色:</span> <select id="sel"> <option value="white" selected>请选择</option> <option value="red">红色</option> <option value="green">绿色</option> <option value="blue">蓝色</option> </select> </body> </html>
Event type (onchange)
Guess you like
Origin www.cnblogs.com/vinson-blog/p/12077512.html
Recommended
Ranking