美文网首页我爱编程
初来乍到(二)

初来乍到(二)

作者: 咔咔咔丶卡布达 | 来源:发表于2018-05-12 22:52 被阅读0次

    再来几道.....

    1. CSS3新增伪类有哪些?(网上一搜都有现成的汇总,自己挑几个记下来)

    选择器 例子 描述
    :nth-child(n) p:nth-child(2) 选择属于其父元素的第二个子元素的每个 <p> 元素。
    :nth-of-type p:nth-of-type(2) 选择属于其父元素第二个 <p> 元素的每个 <p> 元素。
    :checked input:checked 选择每个被选中的 <input> 元素。
    :enabled input:enabled 选择每个启用的 <input> 元素。
    :disabled input:disabled 选择每个禁用的 <input> 元素。
    element1~element2 p~ul 选择前面有 <p> 元素的每个 <ul> 元素。
    attribute*=value a[src*="abc"] 选择其 src 属性中包含 "abc" 子串的每个 <a> 元素。

    2. 用原生js写一个ajax过程(封装好的是在网上找的比较标准,还有一个自己学习时写的简单的,方便记忆....)

    原生js实现Ajax方法(1):

    var Ajax={
      get: function(url, fn) {
        // XMLHttpRequest对象用于在后台与服务器交换数据   
        var xhr = new XMLHttpRequest();            
        xhr.open('GET', url, true);
        xhr.onreadystatechange = function() {
          // readyState == 4说明请求已完成
          if (xhr.readyState == 4 && xhr.status == 200 || xhr.status == 304) { 
            // 从服务器获得数据 
            fn.call(this, xhr.responseText);  
          }
        };
        xhr.send();
      },
      // datat应为'a=a1&b=b1'这种字符串格式,在jq里如果data为对象会自动将对象转成这种字符串格式
      post: function (url, data, fn) {
        var xhr = new XMLHttpRequest();
        xhr.open("POST", url, true);
        // 添加http头,发送信息至服务器时内容编码类型
        xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");  
        xhr.onreadystatechange = function() {
          if (xhr.readyState == 4 && (xhr.status == 200 || xhr.status == 304)) {
            fn.call(this, xhr.responseText);
          }
        };
        xhr.send(data);
      }
    }
    

    忘了可以看这个-->有注释的原文地址
    原生js实现Ajax方法(2):

    <input type="text" name="username" id="username">
    <input type="button" value="提交" id="btn">
    <script>
        var btn = document.getElementById("btn");
        var username = document.getElementById("username");
        btn.onclick = function(){
            var xhr = new XMLHttpRequest();
            xhr.open("post","/checkname");
            xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
            xhr.send("username=" + username.value);
            xhr.onreadystatechange = function(){
                if(xhr.readyState == 4 && xhr.status == 200){
                    var res = xhr.responseText;
                    console.log(res);
                }
            }
        }
    </script>
    

    3. jQuery绑定事件的方法有哪些

    有这些,还是直接看这个吧,主要得理解它们之间的区别。

    4.异步加载js方案

    这个题之前是真的不知道,只知道一种 async的方法,其它两种没怎么了解过,想了解的还是去看牛逼的人写的吧。

    相关文章

      网友评论

        本文标题:初来乍到(二)

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