Blogger Information
Blog 41
fans 2
comment 0
visits 29336
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
jQuery常用dom操作与vue基础语法1
月光下,遗忘黑暗
Original
436 people have browsed it

1.jQuery元素操作

代码块

  1. <!doctype html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta name="viewport"
  6. content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
  7. <meta http-equiv="X-UA-Compatible" content="ie=edge">
  8. <title>Document</title>
  9. </head>
  10. <body>
  11. <ul>
  12. <li class="item">item1</li>
  13. <li class="item">item2</li>
  14. <li class="item">item3</li>
  15. <li class="item">item4</li>
  16. <li class="item">item5</li>
  17. </ul>
  18. <script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.6.0/jquery.js"></script>
  19. <script >
  20. //增
  21. $('.item').eq(3).after('<li class="item">321</li>').next().css('color','red').prev().css('color','red');
  22. // 添加到兄弟节点
  23. $("<h1>hello</h1>").insertBefore('ul');
  24. $("<h1>hello</h1>").insertAfter('ul');
  25. //在原元素上操作replaceWith()
  26. $("h1").replaceWith("<h2>321</h2>");
  27. //替换所有选择的元素
  28. $("<h1>123</h1>").replaceAll('h2');
  29. // 在元素上执行删除操作
  30. $('h1').remove();
  31. //对元素进行克隆
  32. $('.item:first-of-type').clone().prependTo('.item:last-of-type');
  33. </script>
  34. </body>
  35. </html>

效果

2.jQuery的ajax与跨域

代码块

  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <title>Title</title>
  6. </head>
  7. <body>
  8. <button class="get">1. $.get(): 请求数据</button>
  9. <button class="post">2. $.post(): 请求数据</button>
  10. <button class="jsonp">3. $.ajax():JSONP: 跨域请求数据</button>
  11. <script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.6.0/jquery.js"></script>
  12. <script>
  13. $(".get").click(()=>{
  14. $.ajax({
  15. type: "get",
  16. url: "user.php",
  17. data: { id: 3 },
  18. dataType: "html",
  19. success: (data) => console.log(data),
  20. });
  21. })
  22. $('.jsonp').click((ev)=>{
  23. $.ajax({
  24. type :'get',
  25. url : 'http://www.test1.com/test.php?id=2&callback=?',
  26. dataType: 'jsonp',
  27. jsonpCallback : "show",
  28. })
  29. })
  30. function show(data) {
  31. console.log(data);
  32. }
  33. </script>
  34. </body>
  35. </html>

效果图

3.vue基础语法

代码块

  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <title>Title</title>
  6. </head>
  7. <body>
  8. <!--v-bind:可简化为":",为元素绑定普通属性-->
  9. <div class="app" >
  10. <p v-bind:style="['color:red','background:green']">{{site}}</p>
  11. <p v-bind:style="style1">{{site}}</p>
  12. <p>40 + 40 = {{40+40}}</p>
  13. <p>{{flag ? '高兴' : "睡觉"}}</p>
  14. <p>用户名:<span v-text="username"></span></p>
  15. <p>用户名:<span v-once="username"></span></p>
  16. <p>用户名:<span v-html="a"></span></p>
  17. </div>
  18. <div class="app" ></div>
  19. <script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
  20. <script>
  21. const vm = new Vue({
  22. el: '.app',
  23. data:{
  24. site:"php.cn",
  25. style1 : 'color:red',
  26. flag : true,
  27. username : '聂哥',
  28. a : "<h1>555</h1>"
  29. }
  30. })
  31. console.log(vm.$data);
  32. console.log(vm.$el);
  33. console.log(vm.site);
  34. vm.site = 321;
  35. </script>
  36. </body>
  37. </html>

效果

Correcting teacher:天蓬老师天蓬老师

Correction status:qualified

Teacher's comments:
Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post