6.1练习

作者: 行之北斗 | 来源:发表于2019-03-28 11:03 被阅读0次

    购物车

    <!DOCTYPE html>
    <html>
        <head>
            <meta charset="utf-8">
            <title></title>
            <script type="text/javascript">
                function sum(){
                    var chone = document.getElementsByName("chkone");
                    var money = document.getElementsByName("each_money");
                    var summ = 0;
                    for(var i = 0;i<chone.length;i++){
                        if(chone[i].checked){
                            summ+=Number(money[i].value);
                        }
                    }
                    document.getElementById("total").value = summ;
                    
                }
            </script>
        </head>
        <body>
            <form>
                <table border="1" width="400" cellpadding="0" cellspacing="0">
                 <tr>
                 <td width="50">金额</td>
                  <td></td>
                 <td>是否求和</td>
                 </tr>
    
                  <tr>
                 <td width="50"><input type="text" name="each_money"/></td>
                  <td></td>
                 <td><input type="checkbox" name="chkone"/></td>
    
                 </tr>
                  <tr>
                 <td width="50"><input type="text" name="each_money"/></td>
                  <td></td>
                 <td><input type="checkbox" name="chkone"/></td>
                 </tr>
                 <tr>
                 <td width="50"><input type="text" id="total" readonly="readonly" /></td>
                  <td>金额合计</td>
                 <td><input type="button" onclick="sum();" value="求和"/></td>
    
                 </tr>
                </table>
        </form>
        </body>
    </html>
    
    

    全选

    <!DOCTYPE html>
    <html>
        <head>
            <meta charset="utf-8">
            <title></title>
            <script type="text/javascript">
                function all1(){
                    // alert("234");
                    var all = document.getElementById("all");
                    var qx = document.getElementsByName("qx");
                    
                    for(var i = 0;i<qx.length;i++){
                        qx[i].checked=all.checked;
                    } 
                    
                
                }
                
                
                
                function one(){
                    // alert("wer");
                    var all = document.getElementById("all");
                    var qx = document.getElementsByName("qx");
                    var count = 0;
                    for(var i = 0;i<qx.length;i++){
                        if(!qx[i].checked){
                            
                            all.checked=false;
                        }else{
                            count++;
                        }
                        
                        
                    }
                    if(qx.length==count){
                        all.checked = true;
                    }
                    
    /*              if(count==qx.length){
                        
                        
                        all.checked=true;
                    }else{
                        all.checked=false;
                    } */
                }
            </script>
        </head>
        <body>
            <input type="checkbox" name="all" id="all" onclick="all1();" />全选
            <table border="1px" cellspacing="0" cellpadding="0">
                <tr><th><input type="checkbox" name="qx" id="qx"  value="1" onclick="one();"/></th><td>用户1</td></tr>
                <tr><th><input type="checkbox" name="qx" id="qx"  value="2" onclick="one();"/></th><td>用户2</td></tr>
            </table>
        </body>
    </html>
    
    

    相关文章

      网友评论

          本文标题:6.1练习

          本文链接:https://www.haomeiwen.com/subject/xdafbqtx.html