Blogger Information
Blog 16
fans 7
comment 1
visits 11370
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
12月24日- jQuery事件、动画
Eric
Original
690 people have browsed it

一、jQuery 事件

  • .on( events [, selector ] [, data ] )

    1. <button id="btn">按钮</button>
    2. <script>
    3. $(function () {
    4. // 基础事件
    5. $('#btn1').on('click', function () {
    6. alert('按钮被点击了');
    7. });
    8. // 事件传参
    9. function myFunc(event){
    10. alert(event.data.name);
    11. }
    12. $('p').on('click',{name: 'eric'}, myFunc);
    13. // 取消submit 事件
    14. $('form').on('submit',false);
    15. // 阻止action 默认事件
    16. $('form').on('submit',function (event) {
    17. event.preventDefault();
    18. });
    19. // 停止submit 事件向上冒泡
    20. $('form').on('submit',function (event) {
    21. event.stopPropagation();
    22. });
    23. });
    24. </script>

二、jQuery 动画

  • 显示/隐藏
  1. <p>编程语言(programming language)可以简单的理解为一种计算机和人都能识别的语言。</p>
  2. <button id="btn1">显示</button>
  3. <button id="btn2">隐藏</button>
  4. <button id="btn3">显示/隐藏</button>
  5. <script>
  6. $(function () {
  7. // 显示
  8. $('#btn1').click(function () {
  9. $('p').show(1000);
  10. });
  11. // 隐藏
  12. $('#btn2').click(function () {
  13. $('p').hide(1000);
  14. });
  15. // 显示/隐藏
  16. $('#btn3').click(function () {
  17. $('p').toggle(2000);
  18. });
  19. });
  20. </script>
  • 上滑/下拉
  1. <button id="btn1">上滑</button>
  2. <button id="btn2">下拉</button>
  3. <button id="btn3">上滑/下拉</button>
  4. <ul>
  5. <li>产品</li>
  6. <li>用户</li>
  7. <li>文档</li>
  8. </ul>
  9. <p>编程语言(programming language)可以简单的理解为一种计算机和人都能识别的语言。</p>
  10. <script>
  11. $(function () {
  12. // 上滑
  13. $('#btn1').click(function () {
  14. $('ul').slideUp('fast');
  15. });
  16. // 下拉
  17. $('#btn2').click(function () {
  18. $('ul').slideDown('slow');
  19. });
  20. // 上滑/下拉
  21. $('#btn3').click(function () {
  22. $('ul').slideToggle(2000);
  23. });
  24. });
  25. </script>
  • 淡入/淡出
  1. <button id="btn1">淡入</button>
  2. <button id="btn2">淡出</button>
  3. <button id="btn3">淡入/淡出</button>
  4. <ul>
  5. <li>产品</li>
  6. <li>用户</li>
  7. <li>文档</li>
  8. </ul>
  9. <p>编程语言(programming language)可以简单的理解为一种计算机和人都能识别的语言。</p>
  10. <script>
  11. $(function () {
  12. // 淡入
  13. $('#btn1').click(function () {
  14. $('ul').fadeIn('slow');
  15. });
  16. // 淡出
  17. $('#btn2').click(function () {
  18. $('ul').fadeOut('slow');
  19. });
  20. // 淡入/淡出
  21. $('#btn3').click(function () {
  22. $('ul').fadeToggle(2000);
  23. });
  24. });
  25. </script>

THE END !

Correcting teacher:天蓬老师天蓬老师

Correction status:qualified

Teacher's comments:添加事件, 推荐使用on, 尽可能这样, 不要直接以属性添加
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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!