js able to limit the input digital decimal point, js definition array, add data to the array js, js into the numeric character, the results of the division two decimals --js quiz: Calculation scoring

A friend told me to go to a game count points;

Rules: remove the lowest score the highest points averaging points;

Recent study of large data visualization - map, use js something, so today it is thought by js

Use knowledge points:

js able to limit the input digital decimal point, js definition array, add data to the array js, js into a numeric character, dividing the result with two decimal places.

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
</head>
<body>
<div align="center">
        <form action="" method="post" onsubmit="return avg()">
        <thead>
        <tr ><th colspan=2 style= "text-align = left: Center" > match count points </ TH > </ TR > 
        </ thead > 
            < Table > 
                < TR > 
                    < TD > Jury. 1 </ TD > 
                    <-! only numbers can be input decimal. -> 
                    < TD > < INPUT the onkeyup = "IF (isNaN (value)) the execCommand ( 'Use the undo')" onafterpaste = "IF (isNaN (value)) the execCommand ( 'Use the undo')" ID = "score1" > </ TD > 
                </ TR >
                <tr>
                    <td>评委2</td>
                    <td><input onkeyup="if(isNaN(value))execCommand('undo')" onafterpaste="if(isNaN(value))execCommand('undo')" id="score2"></td>
                </tr>
                <tr>
                    <td>评委3</td>
                    <td><input onkeyup="if(isNaN(value))execCommand('undo')" onafterpaste="if(isNaN(value))execCommand('undo')" id="score3"></td>
                </tr>
                <tr>
                    <td>评委4</td>
                    <td><input onkeyup="if(isNaN(value))execCommand('undo')" onafterpaste="if(isNaN(value))execCommand('undo')" id="score4"></td>
                </tr>
                <tr>
                    <td>评委5</td>
                    <td><input onkeyup="if(isNaN(value))execCommand('undo')" onafterpaste="if(isNaN(value))execCommand('undo')" id="score5"></td>
                </tr>
                <tr>
                    <td>评委6</td>
                    <td><input onkeyup="if(isNaN(value))execCommand('undo')" onafterpaste="if(isNaN(value))execCommand('undo')" id="score6"></td>
                </tr>
            </table>            
            <div>
                <button type="submit" >确认</button>
                <button type="reset" >重填</button>
            </div>
        </form>
</div>
<script type="text/javascript">
function avg() {
    var score1 = document.getElementById("score1");
    var score2 = document.getElementById("score2");
    =score3was document.getElementById("score3");
    var score4 = document.getElementById("score4");
    var score5 = document.getElementById("score5");
    var score6 = document.getElementById("score6");

    var s1= parseFloat(score1.value);//强行转换为Float型
    var s2= parseFloat(score2.value);
    var s3= parseFloat(score3.value);
    var s4= parseFloat(score4.value);
    var s5= parseFloat(score5.value);
    var s6= parseFloat(score6.value);

    var score=new Array();
    score[1]=s1;
    score[2]=s2;
    score[3]=s3;
    score[4]=s4;
    score[5]=s5;
    score[6]=s6;
    
    was my = S1;
    were max = S1;    
    for ( was in = 1 ; in <= 6 ; of ++ ) {
         if (min > Score [i]) {
            min=score[i];
        }
    }
    //alert(min);
    for(var i=1;i<=6;i++){
        if(max<score[i]){
            max=score[i];
        }
    }
    // alert (max); 
    were count = 0 ;
    for ( was in = 1 ; in <= 6 ; in ++ ) {
        count=count+score[i];
    }    
    // Alert (COUNT); 
    var count1 is = COUNT - min - max;
     // Alert (count1 is); 
    var scoreavg = count1 is / . 4; 
    // Alert (scoreavg); 
    Alert ( " calculates an average score of "  + scoreavg.toFixed ( 2 )); // two decimals   
}
 </ Script > 
</ body > 
</ HTML >

 Run shot:

 

 

 

 

 

 

Guess you like

Origin www.cnblogs.com/sengzhao666/p/11911493.html