美文网首页
基础知识

基础知识

作者: 郭先生_515 | 来源:发表于2019-03-04 19:22 被阅读0次
    1. 文本溢出 ...
    <!--  (不规定显示行数) -->
    .box {
        overflow: hidden;
        white-space: nowrap;
        text-overflow: ellipsis;
    }
    
    <!--  (可规定显示行数) -->
    .box {
        overflow: hidden;           
        text-overflow: ellipsis;        /* 文本溢出 ... */
        display: -webkit-box;
        -webkit-line-clamp: 2;          /* 规定显示行数... */
        -webkit-box-orient: vertical;
    }
    
    1. 原生添加class 移除class
    let box = document.querySelector('.box');
    // 将 class='box' 改为 class='box1';
    box.className = 'box1';
    // 添加 class
    box.className += ' box1';   // box1前要有空格;
    box.classList.add('box1');   //两种方式
    // 移除 class
    box.classList.remove('box1');
    
    
    // JQuery 添加 移除class
    // 添加 class:
    $(".box").addClass("box1");
    // 移除class
    $(".box").removeClass("box1");
    
    1. 斐波那契数列
    function *fibonacci() {
        let [prev, cur] = [0,1];
        for (;;) {
            [prev, cur] = [cur, prev + cur];
            yield cur;
        }
    }
    for(let n of fibonacci()){
        if (n>1000) {
            break;
        }
            if (n==1) {
                    console.log(n);
            }
        console.log(n);
    }
    
    1. 监听input 和 select 下拉框值改变
     $("#btn").on("click", function() {
        var that = this;
        $(that).attr('disabled', true);
        $(that).css('cursor', 'not-allowed');
        // 获取 input 和 select 值
        var end_time = $('.input_box').val();
        var minute = $("#select_box").val();
        // 监听 input 和 select 改变
        $(".input_box").bind("input propertychange", function() {
            $(that).attr('disabled', false);
            $(that).css('cursor', 'pointer');
        });
        $('#select_box').on("change", function() {
            $(that).attr('disabled', false);
            $(that).css('cursor', 'pointer');
        });
    });
    

    相关文章

      网友评论

          本文标题:基础知识

          本文链接:https://www.haomeiwen.com/subject/gmcwuqtx.html