jQuery小结2

<!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>
    <title></title>
    <script type="text/javascript" src="Scripts/jquery-1.4.1.js"></script>

    <style type="text/css">
        *{margin:0px;padding:0px;}
        body{font-size:12px;}
        
        .box{margin:10px;padding:10px;}
        .box h3{margin:10px 0px;border-bottom:1px solid red;padding-bottom:10px;}
        .box p{line-height:20px;}
        
        #databox{margin:10px;padding:10px;}
        #databox input{margin-top:10px;margin-right:10px;border:1px solid #aaccff;float:left;height:25px;line-height:25px;padding:0px 5px;}
        
    </style>
    <script type="text/javascript">
    $(function(){
        var sum=0;
        $(":text").each(function(){
            var num=parseInt($(this).val());
            sum+=num;
        })
        alert(sum);
    })
    </script>
</head>
<body>
    <div class="box">
        <h3>试题要求</h3>
        <p>
            1.计算所有单元格内数字之和。<br />
            2.将和以对话框的形式弹出。<br />
            <input type="button" value="所有单元格内数字之和" />
        </p>
    </div>

    <div id="databox">
    
        <input type="text" value="1" />
        <input type="text" value="2" />
        <input type="text" value="3" />
        <input type="text" value="4" />
        <input type="text" value="5" />
   
    
        <input type="text" value="6" />
        <input type="text" value="7" />
        <input type="text" value="8" />
        <input type="text" value="9" />
        <input type="text" value="10" />
    
    
        <input type="text" value="11" />
        <input type="text" value="12" />
        <input type="text" value="13" />
        <input type="text" value="14" />
        <input type="text" value="15" />
    
    </div>
</body>
</html>

 

posted on 2015-12-13 22:27  guanzhenqiang  阅读(165)  评论(0编辑  收藏  举报

导航