js 总结累计大全

文本输入框    计算器

<html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 
        <title>无标题</title>
        <script type="text/javascript">
        function sum(obj) {
            var a = document.getElementById("a");
            var b = document.getElementById("b");
            var s = document.getElementById("sum");
            if(a.value === "" || b.value === "") {
                return;
            } 
            s.value = parseInt(a.value) + parseInt(b.value);
        }
        </script>
    </head>
    <body>
        <input type="text" id="a" οnkeyup="sum(this);" />
        <input type="text" id="b" οnkeyup="sum(this);" />
        <input type="text" id="sum" />
    </body>
</html>
复制代码

js全选

复制代码
<SCRIPT type="text/javascript">
$(document).ready(function() {
    $("#checkedAll").click(function(){
        //try{
    if($(this).attr("checked") == true){ //check all
            $("input[name='checkbox_name']").each(function(){
                $(this).attr("checked",true);
            });
        }else{
            $("input[name='checkbox_name']").each(function(){
                $(this).attr("checked",false);
            });
        }
        //}catch(e){
        //alert(e.description+e.name+e.message)
        //}    });
});
</SCRIPT>
    <div class="components-list">
        <input type="checkbox" name="checkbox_name" id="checkbox_name_1" />1<br />
        <input type="checkbox" name="checkbox_name" id="checkbox_name_2" />2<br />
        <input type="checkbox" name="checkbox_name" id="checkbox_name_3" />3<br />
        <input type="checkbox" name="checkbox_name" id="checkbox_name_4" />4<br />
        <input type="checkbox" name="checkedAll" id="checkedAll"/>全选/取消全选
    </div>
复制代码

jQuery获取Select选择的Text和Value:

复制代码
语法解释:
1. $("#select_id").change(function(){
  //code...});   //为Select添加事件,当选择其中一项时触发2. var checkText=$("#select_id").find("option:selected").text();  //获取Select选择的Text3. var checkValue=$("#select_id").val();  //获取Select选择的Value4. var checkIndex=$("#select_id ").get(0).selectedIndex;  //获取Select选择的索引值5. var maxIndex=$("#select_id option:last").attr("index");  //获取Select最大的索引值jQuery设置Select选择的 Text和Value:
语法解释:
1. $("#select_id ").get(0).selectedIndex=1;  //设置Select索引值为1的项选中2. $("#select_id ").val(4);   // 设置Select的Value值为4的项选中3. $("#select_id option[text='jQuery']").attr("selected", true);   //设置Select的Text值为jQuery的项选中
复制代码

 

选中checkbox:

复制代码
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值