推断值的数组

it2025-07-19  3

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html lang="en"> <head>     <meta http-equiv="Content-Type" content="text/html;charset=UTF-8">     <title>Document</title>     <style>         /*css reset開始*/         body,h1,h2,h3,h4,h5,h6,p,dl,dd,ul,ol,pre,form,input,textarea,th,td,select{margin: 0;padding: 0;font-size: 14px;font-family: "Microsoft Yahei";}         input{width: 300px;height: 20px;vertical-align: middle;}         li{list-style: none;vertical-align: top;}         a{text-decoration: none;}         img{border: none;vertical-align: top;}         table{border-collapse: collapse;}         textarea{resize: none;overflow: auto;}         body{margin-top: 10px;}         /*css reset结束*/         form{width: 300px;}         fieldset{margin: 20px;border: 2px dashed palevioletred;}     </style>     <script>         window.onload = function(){             var arr = ['100px', 'abc'-6, [], -98765, 34, -2, 0, '300', , function(){alert(1);}, null, document, [], true, '200px'-30,'23.45元', 5, Number('abc'), function(){ alert(3); }, 'xyz'-90 ];             var oAllnum = document.getElementById('allNum');             var oNum = document.getElementById('Num');             var oMaxNum = document.getElementById('maxNum');             var oNanLocation = document.getElementById('nanLocation');             var arr1 = [];             var arr2 = [];             var arr3 = []; / /            1.数组里全部的数字:↓↓             for(var i=0;i<arr.length;i++){                 if(typeof arr[i] == 'number' && arr[i] === arr[i]){                     arr1.push(arr[i]);                 }             }             oAllnum.value = arr1; //            2.数组里能够转成数字的:↓↓             for(var i=0;i<arr.length;i++){                 if(isNaN(parseInt(arr[i])) == false){                     arr2.push(arr[i]);                 }             }             oNum.value = arr2; //            3.能够转成数字的再从中取最大值:↓↓             var tmp =arr2;             var max = tmp[0];             for(var i=1;i<tmp.length;i++){                 if(max<tmp[i])                 {                     max=tmp[i];                 }             }             oMaxNum.value=max; //            4.NAN所在的位置:↓↓             for(var i=0;i<arr.length;i++){                 if(typeof arr[i] == 'number' && isNaN(Number(arr[i]))){                     arr3.push(i);                 }             }             oNanLocation.value = arr3;         }     </script> </head> <body>     <form action="">         <fieldset>             <legend>输出结果</legend>             arr数组里全部的数字:<input type="text" id="allNum"/><br/><br/>             arr数组里能够转成数字的: <input type="text" id="Num"/><br/><br/>             把转成数字以后的,再取最大值:<input type="text" id="maxNum"/><br/><br/>             NaN所在的位置:<input type="text" id="nanLocation"/>         </fieldset>     </form> </body> </html>

转载于:https://www.cnblogs.com/bhlsheji/p/5036080.html

最新回复(0)