2012-07-28 35 views
3

我使用jQuery獲得一排容器標籤如何獲得內容,並與jQuery

<tr class="phoneNumber"> 
    ABC... 
</tr> 

,當我做$( 「phoneNumber的」)。HTML(),它返回ABC...
有沒有辦法讓

<tr class="phoneNumber"> 
    ABC... 
</tr> 

在此先感謝

+0

[如何獲得innerHtml,包括標籤,使用jQuery?](http://stackoverflow.com/questions/2319213/how-to-get-the-innerhtml-including-the-tag-使用-jquery) – Shyju 2012-07-28 05:16:07

+0

http://stackoverflow.com/questions/2419749/get-selected-elements-outer-html有你的答案 – 2012-07-28 05:18:03

回答

2
(function($) { 
    $.fn.outerHTML = function() { 
    return $(this).clone().wrap('<div></div>').parent().html(); 
    } 
})(jQuery); 

$('.phoneNumber').outerHTML();