zoukankan      html  css  js  c++  java
  • jQuery的一些操作

    用prop('属性')可以获取改属性的值,入判断checkbox是否被选中:

    • $('checkboxid').prop('checked'); //获得返回值 true|false

    控制checkbox的选中/未选中状态

    • $('checkboxid').prop('checked', true);//选中该checkbox
    • $('checkboxid').prop('checked', false);//取消该checkbox选中

    jQueryAjx:

    function ajaxFun() {
       $.ajax( {
             type : 'post',// 提交方式
             dataType : 'json'// 提交数据格式
             data : {  
            'param' : paramVal
          }, url : "../xxx/xxx.do", success : function (data) { var json = eval( "(" + data + ")" ); //格式化JSON }, failure : function (data) {//访问失败后操作 // error to do } }); }

     遍历查找选择列表中选中的值

    $("#id option:selected").each(function(){
       $("#id2").append("<option value='"+$(this).val()+"'>"+ $(this).text() +"</option>");
        $(this).remove();
    });

    用了半天的attr都不可以,用prop就可以了

    $("#inOnPorts p").each(function(i, r){
            $("#inOnPorts p:eq("+i+") input:eq(1)").prop('checked',true)//窗口默认选中关闭
    });
       $("#outOnPorts p").each(function(i, r){
            $("#outOnPorts p:eq("+i+") input:eq(1)").prop('checked',true)//窗口默认选中关闭
    });

    Checkbox

    $(function(){
        $('#chooseall').change(function(){
            if($(this).is(':checked')){
                $('table input[type="checkbox"]').each(function(){
                    $(this).prop('checked',true);
                });
            }else{
                $('table input[type="checkbox"]').each(function(){
                    $(this).prop('checked', false);
                });
            }
        });
    
        $('tr').first().nextAll().on('click',function(){
            if($(this).children().first().children().is(':checked')){
                $(this).children().first().children().prop('checked', false);
            }else{
                $(this).children().first().children().prop('checked', true);
            }
        });
    
    });

    jQuery重置表单方法

    $('#id')[0].reset();

    jQuery通过一个对象查找下级

    $('#id').children('option');

    表格单击事件事件

    $('table tbody tr').on('click',function(){
          if($(this).children().first().children().is(':checked')){
              $(this).children().first().children().prop('checked', false);
            }else{
               $(this).children().first().children().prop('checked', true);
          }
     });

    密码框监听键盘  键入enter调用登录方法

    $(function() {
        $('html').keydown(function(e) {
            if (e.keyCode == 13) {
                LoginResponse();
            }
        });
        var un = $.cookie("username");
        var pwd = $.cookie("password");
        if (un != null && un != "" && un != "null") {
            $("#logUsername").val(un);
        }
        if (pwd != null && pwd != "" && pwd != "null") {
            $("#logPassword").val(pwd);
            $("#remember_me").attr("checked", "checked");
        }
    });

    获取服务器根目录路径

    function download(){ //这是一个下载TOMCAT目录下文件的方法
      window.iframe.location.href="${pageContext.request.contextPath}/resources/x.exe";
    }
  • 相关阅读:
    VC++ 之 文件操作
    Delphi7 API(5) 消息篇:WM_LBUTTONDOWN、WM_LBUTTONUP、WM_MOUSEMOVE
    VC++ 之 输入/输出类库(二)
    VB 访问控制面板
    Delphi7 API(4) 消息_重绘
    Lisp简明教程
    一次快速排序错误引发的思考(2)
    一次快速排序错误引发的思考(1)
    Common Lisp编译程序的小技巧
    暴风影音5免去广告的小技巧
  • 原文地址:https://www.cnblogs.com/timjames/p/8267186.html
Copyright © 2011-2022 走看看