2016-03-09 36 views
0

我一直在嘗試使用jQuery.fn.extend(),它一直在工作,但我想獲得調用它的ID,類或html標記。我無法知道調用我的fn的字符串是標記,ID還是類。 。如何獲取調用我的函數的元素的ID,類或HTML標記?

例如,

$( '表')scrollify();

我希望能夠得到字符串'table'thisscrollify函數內部

這裏是我的代碼:

(function($) { 
 
    $.fn.scrollify = function() { 
 
    $('tbody').css({ 
 
     'width': Math.ceil($('thead').width() + 17) 
 
    }); 
 
    $('tbody > tr > td').css({ 
 
     'width': Math.ceil($('thead').width()) 
 
    }); 
 
    $('thead > tr > th').css({ 
 
     'width': $('tbody').width()/$('thead > tr > th').length 
 
    }); 
 
    $('tbody').css({ 
 
     'margin-top': $('thead').height() - 1 
 
    }); 
 
    return this.get(0).scrollHeight > this.height(); 
 
    }; 
 
})(jQuery); 
 

 
$('table').scrollify();

回答

0

您可以使用this.id獲得ID

this.prop("tagName");以獲取標記名稱

+0

這就是整個問題,我不知道要做什麼,無論是身份證,標籤還是班級 – Kyle

1

一些調整之後和「安慰」 this了很多,我發現,我只需要做到以下幾點:

this.selector

期。