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

搜索
博主信息
博文 33
粉絲 0
評論 0
訪問量 34336
最新下載
更多>
網(wǎng)站特效
網(wǎng)站源碼
網(wǎng)站素材
前端模板
前端 - jQuery - 事件和Ajax
原創(chuàng)
915人瀏覽過

前端 - jQuery - 事件和Ajax

一、事件

  1. <!DOCTYPE html>
  2. <html lang="zh_hans">
  3. <head>
  4. <meta charset="UTF-8" />
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  6. <title>Document</title>
  7. <script src="https://lib.sinaapp.com/js/jquery/1.9.1/jquery-1.9.1.min.js"></script>
  8. </head>
  9. <body>
  10. <ul>
  11. <li>01</li>
  12. <li>02</li>
  13. <li>03</li>
  14. <li>04</li>
  15. </ul>
  16. <form action="">
  17. <input type="email" name="" id="" />
  18. <input type="password" name="" id="" />
  19. <button type="submit">提交</button>
  20. </form>
  21. </body>
  22. <script>
  23. // 3. 事件委派
  24. $("ul").delegate("li", "click", function () {
  25. alert("hello");
  26. });
  27. // 4. 事件切換
  28. $("ul li:first-child").hover(
  29. function () {
  30. $(this).prop("style", "color: red;");
  31. },
  32. function () {
  33. $(this).prop("style", "color: blue;");
  34. }
  35. );
  36. // 5. 事件
  37. //當(dāng)元素失去焦點(diǎn)時觸發(fā)
  38. $("form input[type='email']").blur(function () {
  39. alert("hello");
  40. });
  41. //當(dāng)元素被點(diǎn)擊時觸發(fā)
  42. $("form input[type='email']").click(function () {
  43. alert("world");
  44. });
  45. //當(dāng)提交表單時觸發(fā)
  46. $("form").submit(function () {
  47. alert("已提交");
  48. });
  49. </script>
  50. </html>

二、Ajax

  1. <!DOCTYPE html>
  2. <html lang="zh_hans">
  3. <head>
  4. <meta charset="UTF-8" />
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  6. <title>Document</title>
  7. <script src="https://lib.sinaapp.com/js/jquery/1.9.1/jquery-1.9.1.min.js"></script>
  8. </head>
  9. <body>
  10. <form>
  11. <input type="email" name="email" />
  12. <input type="password" name="password" />
  13. <button type="button">提交</button>
  14. </form>
  15. <div></div>
  16. </body>
  17. <script>
  18. // Ajax操作
  19. $("form button").click(function () {
  20. //序列表表格內(nèi)容為字符串
  21. var data = $("form").serialize();
  22. console.log(data);
  23. $.ajax({
  24. url: "login.php",
  25. type: "POST",
  26. data: data,
  27. dataType: "json",
  28. success: function (res) {
  29. console.log(res);
  30. var str = res.email + res.password;
  31. $("div").html(str);
  32. },
  33. });
  34. });
  35. </script>
  36. </html>
  1. <?php
  2. $email = $_POST['email'];
  3. $password = $_POST['password'];
  4. $arr = array("email"=>$email, "password"=>$password);
  5. $json_obj = json_encode($arr);
  6. echo $json_obj;

四、課程總結(jié)

  • 今天進(jìn)行了 jQuery 的事件處理和Ajax操作,通過上課認(rèn)真聽講和認(rèn)真完成老師布置的作業(yè),使得我對 jQuery的理解和運(yùn)用更加深入和熟悉。最主要的知識點(diǎn)是明白和掌握了事件處理和Ajax的特點(diǎn)以及基本用法。
本博文版權(quán)歸博主所有,轉(zhuǎn)載請注明地址!如有侵權(quán)、違法,請聯(lián)系admin@php.cn舉報處理!
全部評論 文明上網(wǎng)理性發(fā)言,請遵守新聞評論服務(wù)協(xié)議
0條評論
作者最新博文
關(guān)于我們 免責(zé)申明 意見反饋 講師合作 廣告合作 最新更新
php中文網(wǎng):公益在線php培訓(xùn),幫助PHP學(xué)習(xí)者快速成長!
關(guān)注服務(wù)號 技術(shù)交流群
PHP中文網(wǎng)訂閱號
每天精選資源文章推送
PHP中文網(wǎng)APP
隨時隨地碎片化學(xué)習(xí)
PHP中文網(wǎng)抖音號
發(fā)現(xiàn)有趣的

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

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