代码之家  ›  专栏  ›  技术社区  ›  oshirowanen

页面加载jquery

  •  0
  • oshirowanen  · 技术社区  · 14 年前

    我有一个jquery单击事件,它在单击元素时运行。是否可以在加载页面时使其运行一次?

    5 回复  |  直到 14 年前
        1
  •  4
  •   KeatsKelleher    14 年前
    $(document).ready(function(){
    //do something here
    });
    
        2
  •  1
  •   fcalderan    14 年前
    $(document).ready(function(){
    
      $('#yourelement').bind('click', function() {
         /* set handler onclick */
    
      })
      /* trigger ('run once') on domready */
      .trigger('click'); 
    
    
    });
    
        3
  •  1
  •   Jamiec    14 年前

    click()

    $(document).load(function(){
    
       $('#someelement').click(function(){
          alert("some element clicked");
       });
    
       $('#someelement').click();
       // or $('#someelement').trigger('click');
    });
    

    http://jsfiddle.net/ZXyJH/

        4
  •  0
  •   bla    14 年前

    here

    <script type="text/javascript" 
            src="http://www.google.com/jsapi"></script>
    <script type="text/javascript">
      // You may specify partial version numbers, such as "1" or "1.3",
      //  with the same result. Doing so will automatically load the 
      //  latest version matching that partial revision pattern 
      //  (e.g. 1.3 would load 1.3.2 today and 1 would load 1.4.2).
      google.load("jquery", "1.4.2");
    
      google.setOnLoadCallback(function() {
        // Place init code here instead of $(document).ready()
      });
    </script>
    
        5
  •  0
  •   Paul Speranza    14 年前