亚洲国产日韩欧美一区二区三区,精品亚洲国产成人av在线,国产99视频精品免视看7,99国产精品久久久久久久成人热,欧美日韩亚洲国产综合乱

搜索
博主信息
博文 145
粉絲 7
評論 7
訪問量 198606
最新下載
更多>
網(wǎng)站特效
網(wǎng)站源碼
網(wǎng)站素材
前端模板
03月05日作業(yè):過濾器和Ajax
李東亞1??3????12?
原創(chuàng)
954人瀏覽過

作業(yè)一

一、demo代碼練習:
1、代碼

  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <script src="http://upcdn.b0.upaiyun.com/libs/jquery/jquery-2.0.3.min.js"></script>
  6. <title>Document</title>
  7. <style>
  8. .red{
  9. background-color: burlywood;
  10. }
  11. #blue {
  12. color:blue;
  13. }
  14. .blue {
  15. font-size: 20px;
  16. }
  17. </style>
  18. </head>
  19. <body>
  20. <ul id="first">
  21. <li>item1</li>
  22. <li>item2</li>
  23. <ul>
  24. <li>item3-1</li>
  25. <li class="red">item3-2</li>
  26. <li id="blue">item3-3</li>
  27. </ul>
  28. <li>item4</li>
  29. <li>item5</li>
  30. </ul>
  31. <hr>
  32. <ul id="second">
  33. <li class="blue">item1</li>
  34. <li>item2</li>
  35. <li>item3</li>
  36. <li>item4</li>
  37. <li>item5</li>
  38. </ul>
  39. <script>
  40. var li = $('#second > li').filter(":nth-child(-n+3)");
  41. // console.log(li.text());//$()有遍歷的效果
  42. var children =$('li');
  43. // console.log(children);
  44. children.first().css('color','red');
  45. children.last().css('color','green');
  46. children.eq(5).addClass('red');
  47. // console.log(children.find('#blue'));
  48. li = $('li');
  49. // console.log(typeof(li.find('.blue')));
  50. var ul=$('#second');
  51. console.log(ul.find('.blue'));
  52. ul.find('.blue').css('background','lightblue');
  53. var child=$('#second > li');
  54. console.log(child.slice(1,3).text());//索引0開始,取前不取后,如果只有一個參數(shù),直接取到結束
  55. console.log(child.slice(0,-1).text());//尾部索引從-1開始
  56. child.not(':last-child()').css('background','red');
  57. </script>
  58. </body>
  59. </html>

2、運行結果:

二、demo1.html
1、代碼代碼練習

  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <script src="http://upcdn.b0.upaiyun.com/libs/jquery/jquery-2.0.3.min.js"></script>
  6. <title>事件</title>
  7. <style>
  8. form {
  9. width: 200px;
  10. display: grid;
  11. gap: 10px;
  12. }
  13. </style>
  14. </head>
  15. <body>
  16. <form action="a.php">
  17. <input type="text" placeholder="UserName" autofocus>
  18. <input type="password" placeholder="Password">
  19. <button>提交</button>
  20. </form>
  21. <script>
  22. $('form').submit(function(ev){
  23. ev.preventDefault();
  24. });
  25. var user=$('input[type=text]');
  26. // 當元素失去焦點時blur() 函數(shù)觸發(fā) blur 事件,或者如果設置了 function 參數(shù),該函數(shù)也可規(guī)定當發(fā)生 blur 事件時執(zhí)行的代碼。
  27. user.blur(function(){
  28. var tips='';
  29. var users=['admin','peter','ldy','jquery'];
  30. if($(this).val().length===0){
  31. tips='名字不能為空';
  32. $(this).focus();
  33. /*indexOf() 方法可返回某個指定的字符串值在字符串中首次出現(xiàn)的位置。
  34. indexOf() 方法對大小寫敏感!
  35. 如果要檢索的字符串值沒有出現(xiàn),則該方法返回 -1。
  36. */
  37. }else if (users.indexOf($(this).val())===-1){
  38. tips='用戶名不存在'+'<a href="register.php">注冊</a>';
  39. $(this).focus();
  40. }else{
  41. tips= '<i style="color: green">驗證通過<i>';
  42. $('input[type=password]').focus();
  43. }
  44. if($(this).next().get(0).tagName !=='SPAN'){
  45. $('<span>').html(tips).css('color','red').insertAfter($(this));
  46. }
  47. user.on('keydown',function(){
  48. $(this).next('span').remove();
  49. });
  50. })
  51. </script>
  52. </body>
  53. </html>

2、運行效果圖

三、demo2.html代碼練習
1、代碼:

  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <script src="http://upcdn.b0.upaiyun.com/libs/jquery/jquery-2.0.3.min.js"></script>
  6. <title>Document</title>
  7. </head>
  8. <body>
  9. <nav></nav>
  10. <button>get獲取</button>
  11. <div></div>
  12. <button>post獲取</button>
  13. <div></div>
  14. <button>Ajax獲取</button>
  15. <div></div>
  16. <script>
  17. $('nav').load('try.html');
  18. var url='test.php?id=3';
  19. $('button').first().click(function(){
  20. $.get(url,function(data){
  21. $('div').first().html(data);
  22. })
  23. });
  24. $('button').eq(1).click(function(){
  25. $.post('test.php',{id:1},function(data){
  26. $('div').eq(1).html(data);
  27. })
  28. });
  29. $('button').last().click(function(){
  30. $.ajax({
  31. type:'GET',
  32. url:'test.php',
  33. data:{id:1},
  34. dataType:'html',
  35. success:function(data){
  36. $('div').last().html(data);
  37. }
  38. })
  39. })
  40. </script>
  41. </body>
  42. </html>

2、運行結果

三、案例練習
1、代碼:

  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <script src="http://upcdn.b0.upaiyun.com/libs/jquery/jquery-2.0.3.min.js"></script>
  6. <title>Document</title>
  7. <style>
  8. form {
  9. width: 200px;
  10. display: grid;
  11. gap: 10px;
  12. }
  13. .success {
  14. color: green;
  15. }
  16. .fail {
  17. color: red;
  18. }
  19. </style>
  20. </head>
  21. <body>
  22. <form action="">
  23. <input type="text" placeholder="UserName" autofocus>
  24. <input type="password" placeholder="Password">
  25. <button>提交</button>
  26. </form>
  27. <script>
  28. $('form').submit(function (ev) {
  29. ev.preventDefault();
  30. var user = {
  31. 'username': $('input[type=text]').val(),
  32. 'password': $('input[type=password]').val()
  33. }
  34. $.ajax({
  35. type: 'POST',
  36. url: 'check.php',
  37. data: user,
  38. dataType: 'json',
  39. success: function (data) {
  40. if ($('form span').length === 0) {
  41. $('<span>').text(data.message).addClass(function () {
  42. return data.status === 1 ? 'success' : 'fail';
  43. }).appendTo('form');
  44. }
  45. }
  46. });
  47. $('form input').keydown(function () {
  48. $('form').find('span').remove();
  49. });
  50. });
  51. </script>
  52. </body>
  53. </html>

2、運行效果圖

作業(yè)二:

一、相關知識點(jquery對象有獲取輸出有遍歷效果)
1、filter();:過濾器,縮小范圍來命中元素
2、children();:獲取所有子元素
3、first();last();直接獲取第一個或者最后一個元素
4、eq(n);:直接獲取n個元素,n從0開始
5、find();:在所有層級種進行查詢
6、slice();:從jQuery對象集合種選擇一部分,兩參數(shù),索引0開始,取前不取后,如果只有一個參數(shù),直接取到結束;尾部索引從-1開始
7、去表單默認提交事件:$('form').submit(function(ev){ev.preventDefault();});
8、blur(回調(diào)函數(shù));:表單文本框失去焦點時進行驗證;
9、user.indexOf(value);方法可返回某個指定的字符串值在字符串中首次出現(xiàn)的位置。indexOf() 方法對大小寫敏感!如果要檢索的字符串值沒有出現(xiàn),則該方法返回 -1。
10、事件行為:click點擊keydown按下鍵盤任意鍵;
11、$.get():以GET方式從服務器獲取數(shù)據(jù):
$.get(url,[data],[callback],[type])
url:待載入頁面的URL地址
data:待發(fā)送 Key/value 參數(shù)。
callback:載入成功時回調(diào)函數(shù)。
type:返回內(nèi)容格式,xml, html, script, json, text, _default。
12、$.post():以POST方式從服務器獲取數(shù)據(jù);
$.post(url,[data],[callback],[type])
test.php為目標文件,{id:1}數(shù)據(jù)信息
13、load(url,[data,[callback]]): 獲取html代碼片斷,默認get$('nav').load('test.html');
14、$.getJSON(url,[data],[callback])獲取json數(shù)據(jù):
url:發(fā)送請求地址。
data:待發(fā)送 Key/value 參數(shù)。
callback:載入成功時回調(diào)函數(shù)。
15、$.ajax()從服務器獲取數(shù)據(jù)

  1. $.ajax({
  2. type: 'GET', // 請求類型
  3. url: url, // 請求地址
  4. data: data, // 發(fā)送的數(shù)據(jù)
  5. dataType: // 期望的響應數(shù)據(jù)的類型,如json,html,text...,自動判斷
  6. success: 成功回調(diào)
  7. })

16、php數(shù)組:in_array($id, array_column($users, 'id'))
in_array():判斷$id是否在array_column()返回的數(shù)組中
array_column($user,’id’);取出組中id的值重新組成數(shù)組

批改老師:天蓬老師天蓬老師

批改狀態(tài):合格

老師批語:教學源碼原樣照抄不太好, 你可以有自己的想法
本博文版權歸博主所有,轉載請注明地址!如有侵權、違法,請聯(lián)系admin@php.cn舉報處理!
全部評論 文明上網(wǎng)理性發(fā)言,請遵守新聞評論服務協(xié)議
0條評論
關于我們 免責申明 意見反饋 講師合作 廣告合作 最新更新
php中文網(wǎng):公益在線php培訓,幫助PHP學習者快速成長!
關注服務號 技術交流群
PHP中文網(wǎng)訂閱號
每天精選資源文章推送
PHP中文網(wǎng)APP
隨時隨地碎片化學習
PHP中文網(wǎng)抖音號
發(fā)現(xiàn)有趣的

Copyright 2014-2025 http://ipnx.cn/ All Rights Reserved | php.cn | 湘ICP備2023035733號

  • 登錄PHP中文網(wǎng),和優(yōu)秀的人一起學習!
    全站2000+教程免費學