jquery元素获取

children() 获取子元素
siblings() 获取所有的兄弟元素
parent() 获取父元素

  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  6. <title>Document</title>
  7. <script src="https://cdn.bootcss.com/jquery/3.4.1/jquery.js"></script>
  8. </head>
  9. <body>
  10. <!-- 兄弟,父子节点 -->
  11. <ul>
  12. <li>html</li>
  13. <li>css</li>
  14. <li>javascript</li>
  15. </ul>
  16. <!--
  17. children()
  18. siblings()
  19. parent()
  20. 获取所有的兄弟元素 -->
  21. <script>
  22. $("li").click(function(){
  23. $(this).css({color:"red"}).siblings().css({color:"green"})
  24. })
  25. console.log($("ul").parent())
  26. </script>
  27. </body>
  28. </html>

事件

$(document).ready({}) 文档完全加载完后,不包含外部的资源文件的(图片,视频,音频)
window.onload = function(){} 等页面和外部的资源文件都加载完毕,才会执行函数中的内容

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <img src="" alt="">
    <p>hello world</p>
    <script>
        //文档完全加载完后,不包含外部的资源文件的(图片,视频,音频)
        // $(document).ready({

        // })
        // 简写
        $(function(){

        })
        /* 等页面和外部的资源文件都加载完毕,才会执行函数中的内容 */
        window.onload = function(){

        }
    </script>
</body>
</html>

then

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="https://unpkg.com/axios/dist/axios.min.js"></script>
</head>
<body>
    <script>
        /* axios 是一个promise */
        var url ="http://localhost:8000/more"
        axios.get(url).then(res=>{
            console.log(res)
        })
    </script>
</body>
</html>