zoukankan      html  css  js  c++  java
  • jquery 使用 点滴

    1、简单的按钮js事件 用于判断和显示提示

    <script type="text/javascript" language="javascript">

        $(document).ready(function () {
            $("#btnlogin").click(function () {
                $("#lblInfo").html("");
                var uid = $.trim($("#txtUsername").val());
                var pwd = $.trim($("#txtPassword").val());
                if (uid == "") {
                    $("#lblInfo").html("账号不能为空");
                    $("#txtUsername").focus();
                    return false;
                }
                if (pwd == "") {
                    $("#lblInfo").html("密码不能为空");
                    $("#txtPassword").focus();
                    return false;
                }
            });

        });

    </script>

    2、下拉列表的处理

        function dropTypeChange()
        {   
            var sel = $("#<%=dropType.ClientID %>  option:selected").val();
            if(sel=="-1")
            {
               $("#<%=txtNo.ClientID %>").attr('disabled',true);
            }
            else
            {
               $("#<%=txtNo.ClientID %>").attr('disabled',false);
            }
        }

      

    //获取第一个option的值     
    $('#test option:first').val();     
    //最后一个option的值      
    $('#test option:last').val();     
    //获取第二个option的值     
    $('#test option:eq(1)').val();     
    //获取选中的值     
    $('#test').val();     
    $('#test option:selected').val();     
    //设置值为2的option为选中状态     
    $('#test').attr('value','2');     
    //设置第一个option为选中     
    $('#test option:last').attr('selected','selected');     
    $("#test").attr('value' , $('#test option:last').val());     
    $("#test").attr('value' , $('#test option').eq($('#test option').length - 1).val());     
    //获取select的长度     
    $('#test option').length;     
    //添加一个option     
    $("#test").append("<option value='9'>ff</option>");     
    $("<option value='9'>ff</option>").appendTo("#test");     
    //添除选中项     
    $('#test option:selected').remove();     
    //指定项选中     
    $('#test option:first').remove();     
    //指定值被删除     
    $('#test option').each(function(){     
        if( $(this).val() == '5'){     
            $(this).remove();     
        }     
    });     
    $('#test option[value=5]').remove();     
         
    //获取第一个Group的标签     
    $('#test optgroup:eq(0)').attr('label');     
    //获取第二group下面第一个option的值      
    $('#test optgroup:eq(1) :option:eq(0)').val(); 

  • 相关阅读:
    PKU 3984 迷宫问题
    九度 1341 艾薇儿的演唱会
    九度 1335
    SDUT 1198 鞍点计算
    POJ 1363 Rails
    SDUT 1570 C旅行
    HDU 1042 N!
    SDUT 1568 俄罗斯方块
    HDU 1257 最少拦截系统
    POJ 3750 小孩报数问题
  • 原文地址:https://www.cnblogs.com/freeliver54/p/2051000.html
Copyright © 2011-2022 走看看