Blogger Information
Blog 37
fans 1
comment 0
visits 27037
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
1224_jquery节点查找、事件绑定、动画 第39课
叮叮当当
Original
1153 people have browsed it

1、节点查找

  1. <div id="menu">
  2. <label style="background: lightseagreen;color: white">网易云</label>
  3. <div>
  4. <p>Over My Head</p>
  5. <p>Rodeo</p>
  6. <p>I Like it</p>
  7. <p>Lost The Game</p>
  8. <p>Freedom</p>
  9. <p>You're Somebody Else</p>
  10. <p>Edge Of The Night</p>
  11. <p>Coming Down</p>
  12. <p>Dance Monkey</p>
  13. <p>If We Have each Other</p>
  14. </div>
  15. <p>心跳呼吸正常</p>
  16. <p>地尽头</p>
  17. <p class="hides">句号</p>
  18. <p>摩天动物园</p>
  19. </div>
  20. <button onclick="childrens()">children</button>
  21. <button onclick="finds()">find</button>
  22. <button onclick="siblings()">siblings</button>
  23. <button onclick="parents()">parent</button>
  24. <script type="text/javascript">
  25. function childrens() {
  26. // $('#menu').children('p').remove(); //子节点
  27. // $('#menu').children('p:first').remove();
  28. // $('#menu').children('p').first().remove();
  29. $('#menu').children('p').eq(0).remove();
  30. }
  31. function finds() {
  32. // console.log($('#menu').find('p[class="hides"]'));
  33. // console.log($('#menu').find('p:first')); //后代节点
  34. // console.log($('#menu').find('p:last'));
  35. // console.log($('#menu').find('p').eq(1));
  36. $('#menu').find('p').eq(1).remove();
  37. }
  38. function siblings() {
  39. // console.log($('p[class="hides"]').siblings()); //兄弟节点
  40. // console.log($('p[class="hides"]').siblings('p'));
  41. // console.log($('p[class="hides"]').siblings('p:last'));
  42. $('p[class="hides"]').siblings('p:last').remove();
  43. }
  44. function parents() {
  45. // console.log($('div[class="hides"]').parent().attr('id')); //父节点
  46. $('div[class="hides"]').parent().remove();
  47. }
  48. </script>

2、事件绑定

  1. <input type="text" name="user" placeholder="请填入姓名">
  2. <hr>
  3. <select name="hobby">
  4. <option value="eat">吃饭</option>
  5. <option value="sleep">睡觉</option>
  6. <option value="hit doudou">打豆豆</option>
  7. <option value="happy to hit doudou">快乐地打豆豆</option>
  8. </select>
  9. <hr>
  10. <table>
  11. <thead>
  12. <tr>
  13. <th>ID</th>
  14. <th>姓名</th>
  15. <th>性别</th>
  16. <th>年龄</th>
  17. </tr>
  18. </thead>
  19. <tbody>
  20. <tr>
  21. <td>1</td>
  22. <td>范小爷</td>
  23. <td></td>
  24. <td>23</td>
  25. </tr>
  26. <tr>
  27. <td>2</td>
  28. <td>若若</td>
  29. <td></td>
  30. <td>18</td>
  31. </tr>
  32. </tbody>
  33. </table>
  34. <button onclick="binds()">on事件</button>
  35. <script type="text/javascript">
  36. function binds() {
  37. // $('table tbody' ).on('click','tr',function () {
  38. // console.log( $(this).text() );
  39. // });
  40. $('table tbody' ).on('dblclick','tr',function () {
  41. console.log( $(this).text() );
  42. });
  43. // $('table tbody' ).on('mouseover','tr',function () {
  44. // console.log( $(this).text() );
  45. // });
  46. }
  47. function __init() {
  48. $('input[name="user"]').on('blur',function () { // $().blur(function(){});
  49. var txt = $(this).val();
  50. if( txt=='' ){
  51. $(this).css('border','solid 1px red');
  52. }else{
  53. $(this).css('border','solid 1px #e5e5e5');
  54. }
  55. });
  56. $('select[name="hobby"]').on('change',function () {
  57. var val = $(this).val();
  58. alert(val);
  59. });
  60. }
  61. __init();
  62. </script>

3、动画

  1. <div name="mydiv">
  2. <p>php教程</p>
  3. <p>java教程</p>
  4. <p>c#教程</p>
  5. </div>
  6. <div id="mydiv" flag=0></div>
  7. <button onclick="shows()" style="margin-top:200px;">show</button>
  8. <button onclick="larges()">large</button>
  9. <button onclick="smalls()">small</button>
  10. <script type="text/javascript">
  11. $('div[name="mydiv"]').mouseover(function () {
  12. $(this).hide(1000);
  13. });
  14. function shows() {
  15. // $('div[name="mydiv"]').show(1000);
  16. $('div[name="mydiv"]').slideDown(1000); //向下显示
  17. // $('div[name="mydiv"]').slideUp(1000); //向上隐藏
  18. }
  19. function larges() {
  20. $('#mydiv').animate( {width:'+=100',height:'+=100'}, 1000 );
  21. }
  22. function smalls() {
  23. $('#mydiv').animate( {width:'-=100',height:'-=100'}, 1000 );
  24. }
  25. function breath() {
  26. var flag = $('#mydiv').attr('flag');
  27. if( flag==0 ){
  28. $('#mydiv').animate( {width:'+=100',height:'+=100'}, 1000 );
  29. $('#mydiv').attr('flag',1);
  30. }
  31. if( flag==1 ){
  32. $('#mydiv').animate( {width:'-=100',height:'-=100'}, 1000 );
  33. $('#mydiv').attr('flag',0);
  34. }
  35. }
  36. // setInterval(breath,2000); //自动放大缩小
  37. </script>

Correcting teacher:天蓬老师天蓬老师

Correction status:qualified

Teacher's comments:jQuery是不是很意思呢
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