zoukankan      html  css  js  c++  java
  • 自己项目一些用到的jq方法

    1,这样可以给未来元素添加事件

    $(document).on("click", ".title-r", function() {}

    2,输入框输入事件,感觉比聚焦好用,限制字数,根据输入字数显示长度

    $(".text-box").bind("input propertychange",function(){
            var put = $(this).next(".num").find('.put');
            var max = $(this).next(".num").find('.max');
            var val = $(this).val();
            var lgh = $(this).val().length;
            var maxlgh = parseInt($(max).text());
            if(lgh>maxlgh){
                $(this).val(val.substring(0,maxlgh));
                $(put).text(maxlgh);
            }else{
                $(put).text(lgh);
            }
        });

    3,change事件,用在input:file这里了

    $(".file-input").change(function(){
            var val = $(this).val();
            if(!val==""){
                $(this).next(".file-img").removeClass("hide").attr("src",val);
                $(this).next().next(".del-img").removeClass("hide");
            }
        });

    4,滚动条事件,让一块dom随着滚动条事件触发定位效果

    $(window).scroll(function() {
                    if($(window).scrollTop() > 135) {
                        $('.new-r-phone').css({
                            "position": "fixed",
                            "margin": "-130px 0 0 0"
                        })
                    }else{
                        $('.new-r-phone').css({
                            "position": "relative",
                            "margin": "0 0 0 0"
                        })
                    }
                });

    5,获得高度,设置高度

    var height = $(".newtask-l").height();
    $(".newtask-r").height(height);

    6,引入公共部分,比如头部

    $(document).ready(function() {
        $(".header").load("public-header.html");
    });

    7,遍历,我这是遍历的单选复选框

    $.each($('input:checkbox,input:radio'), function() {
        if(this.checked) {
            $(this).next('b').css({
                background: "#5C6AC0",
                border: "none",
                 "17px",
                height: "17px"
            })
        }
    });

    8,给select下拉加事件,用的change,给选项加上val值

    $(".send-way").bind("change", function() {
        if($(this).val() == 1) {
            $(".news-center,.up-pic").addClass('hide')
        }
        if($(this).val() == 2) {
            $(".news-center").removeClass('hide')
            if($(".news-model").val() == 2) {
                $(".up-pic").removeClass('hide')
            }
        }
    })

    9,获得下标,或者通过下标选择之后进行操作

    var index = $(this).parent().parent().index();
    $('.pcd').eq(index).remove();

    10,find和childeren的区别,find是找到子元素里面所有符合条件的,包括子元素里面的子元素,children是找到亲子元素,不会往子元素下面继续找

  • 相关阅读:
    Linux指令集
    [日记]贝鲁特煎熬第32天
    2019南京区域赛ABCHJK题解 & KMbfs(O(n^3))板子
    欧拉筛质数以及四大积性数论函数(欧拉函数、莫比乌斯函数、约数个数函数、约数和函数)
    简短的自我介绍
    BSTTreap名次树数组&指针实现板子 Ver1.0
    2019银川区域赛BDFGHIKN题解
    安装vs2010
    SPEmailEventReceiver 之导入附件EXCEL
    为incoming mail绑定事件,SPEmailEventReceiver
  • 原文地址:https://www.cnblogs.com/zongyuan/p/8981639.html
Copyright © 2011-2022 走看看