The example in this article describes the stretch and shrink menu code implemented in JavaScript. Share it with everyone for your reference. The details are as follows:
The screenshot of the running effect is as follows:
The specific code is as follows:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=gb2312" /> <title>JavaScript获取数组最大值和最小值</title> <script type="text/javascript"> //获取数组最大值 function findMax() { var arr = [3,4,76,2,54,23,78,90,89,99,234,12,23,76,89,90]; var max = Array.max(arr); document.getElementById("max").value = max; } //获取数组最大值函数 Array.max = function(arr) { return Math.max.apply(Math,arr); } //获取数组最小值 function findMin() { var arr = [34,4,3,67,89,30,23]; var min = Array.min(arr); document.getElementById("min").value = min; } //获取数组最小值函数 Array.min = function(arr) { return Math.min.apply(Math,arr); } window.onload = function(){ findMax(); findMin(); }; </script> </head> <body> <label>数组最大值:</label> <input type="text" id="max"/> <label>数组最小值:</label> <input type="text" id="min"/> </body> </html>
I hope this article will be helpful to everyone learning JavaScript programming.