很多js jquery 初学者对于AJAX 异步的地址加class id 不是很明白,写一个DEMO 希望对于大家有帮助。

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="https://apps.bdimg.com/libs/jquery/2.1.4/jquery.min.js"></script>
</head>

<body>

    <style>

    </style>

    <div>这是AJAX获得的和简单内容</div>
    <button>AJAX获取内容</button>


    <script>
        $(function() {
            $('button').click(function() {
                $('div').load('/1.txt #p1');
            })
        })
    </script>
</body>

</html>


1.txt 内容如下:

<h2>jQuery and AJAX is FUN!!!</h2>
<p id="p1">This is some text in a paragraph.</p>

 $('div').load('/1.txt #p1');
传的CLASS id 如上!!!!!

发表评论