zoukankan      html  css  js  c++  java
  • jQuery AJAX与jQuery事件的分析讲解

    jQuery 本身即是为事件处理而特别设计的,jQuery 事件处理方法是 jQuery 中的核心函数。

    $(function() { ... }); 是如下格式的缩写:

    ?
    1
    $(document).ready(function() { ... });

    0. $ 符号

    根据类别,定位标签:

    ?
    1
    2
    3
    4
    5
    6
    <button>click me</button>
    <p>hide me</p>
    <p>hide me 2</p>
    $('button').click(function(){
      $('p').hide();     // 作用在两个 <p>/</p> 上
    });

    根据 id 定位标签:

    ?
    1
    2
    <h2 id='temp'></p>
    $('#temp').html(...);

    1. demo:点击按钮,将段落折叠

    ?
    1
    2
    3
    4
    5
    $(document).ready(function () {
      $('button').click(function(){
        $('p').hide();
      });
    });

    2. jQuery ajax - getJSON() 方法

    使用 AJAX 请求来获得 JSON 数据,并输出结果:

    ?
    1
    2
    3
    4
    5
    6
    7
    $("button").click(function(){
     $.getJSON("demo_ajax_json.js",function(result){
      $.each(result, function(i, field){        // 遍历数组
       $("div").append(field + " ");
      });
     });
    });

     

  • 相关阅读:
    愚人节的礼物
    Image Transformation
    Rails
    Google Map
    Code Formatter
    ACboy needs your help again!
    Geek's Collection(幂运算)
    Train Problem I
    Beautiful Meadow
    Card Trick(模拟)
  • 原文地址:https://www.cnblogs.com/good10000/p/10612979.html
Copyright © 2011-2022 走看看