jQuery---jQuery初体验

jQuery初体验

1. 引入jquery文件

2. 入口函数标准

jQuery优点总结 (对应的就是js的缺点):

  • 查找元素的方法多种多样,非常灵活
  • 拥有隐式迭代特性,因此不需要手写for循环
  • 完全没有兼容性问题
  • 实现动画非常简单,而且功能更加强大
  • 代码简单粗暴
<!DOCTYPE html>
<html lang="zh-CN">

<head>
  <meta charset="UTF-8">
  <title>Title</title>
  <style>
    div {
      height: 200px;
      margin-bottom: 10px;
      background-color: #a43035;
      display: none;
    }
  </style>

  <!-- 1.引入jquery文件 -->
  <script src="jquery-1.12.4.js"></script>
  <script>
    //2. 入口函数的标准
    $(document).ready(function () {
      //获取对象,注册事件,把on去掉,是一个方法
      $("#btn1").click(function () {
        //隐式迭代:偷偷的遍历,jQuery会自动的遍历,不需要我们遍历。
        $("div").show(1000);
      });
      $("#btn2").click(function () {
        $("div").text("我是内容");
      });
    });
  </script>

</head>

<body>

  <input type="button" value="btn1" id="btn1">
  <input type="button" value="设置内容" id="btn2">

  <div></div>
  <div></div>
  <div></div>


</body>

</html>

猜你喜欢

转载自www.cnblogs.com/jane-panyiyun/p/12195425.html
今日推荐