2011-06-08 152 views
0

我試圖找出如何正確創建jquery插件。這是我做的jquery插件問題

(function($){ 

      $.fn.myPlugin = function() { 
      console.log(this.eq(0).text()); 
      }; 
     })(jQuery); 

$('#sector1').myPlugin(); 

這裏是HTML

<div id="sector1"> 
     <span class="timestamp">1</span> 
    </div> 
    <div id="sector2"> 
     <span class="timestamp">2</span> 
    </div> 

的問題是,我不能讓扇區1跨度標籤的文字。 如何做到這一點?

回答

0
(function($) { 
    $.widget("ui.myplugin", { 
     _init: function() { 
      var text = $("#sector1 .timestamp", this.element).html(); 
     } 

    }); 
})(jQuery);