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>

效果

更多相关文章

  1. 用urllib库几行代码实现最简单爬虫
  2. 尚能饭否|技术越来越新,我对老朋友jQuery还是一如既往热爱
  3. jQuery:常用 jQuery方法,$()的四种类型参数,jQuery对象转js对象方
  4. Requests库快速学习
  5. Python列表操作最全面总结
  6. ADAS系统传统燃油车动力执行策略详解(一)
  7. 【秒杀】一、系统设计要点,从卖病鹅说起
  8. 深入了解Nginx
  9. 【jQuery基础入门】jQuery中常用Dom操作总结及Ajax异步请求和jso

随机推荐

  1. Android调用系统应用程序
  2. How to import sample Android projects
  3. linux下搭建android NDK开发环境
  4. 第五章 以数据为中心—数据存取(4)
  5. android 注册页面实现
  6. 【30篇突击 android】源码统计八
  7. Android(安卓)实现简单的登陆注册功能(Sha
  8. android推送学习——google的C2DM
  9. WARNING: APP_PLATFORM android-14 is la
  10. android文章 - 收藏集 - 掘金