2014-03-13 37 views
0

我在JQuery的工作之前,我有點不明白我怎麼可以在原型如何通過類名原型

<div class="quote_content"> 
    <a>asd</a> 
</div> 

由於得到.quote_content<a>asd</a>得到DIV的HTML!

UPDATE

我有做一個函數:

<script type="text/javascript">// <![CDATA[ 
function showCompare() { 
    var quote_content = $$(".quote_content"); 
    win = new Window({className: "mac_os_x", title: "Sample", width:800, height:400, destroyOnClose: true, recenterAuto:false}); 

    win.getContent().innerHTML = quote_content; 
    win.showCenter(); 
} 
// ]]></script> 

quote_content輸出[object HTMLDivElement]

回答

2

試試這個,如果你想要做的就是去通過頁面發現任何元素與類名quote_content並返回它的HTML內容:

$$('.quote_content').each(function(elm){ 
    // do whatever you like with elm.innerHTML 
    alert(elm.innerHTML); 
    // note that any whitespace, as in your example 
    // will be preserved. You may prefer this instead: 
    var child = elm.down(); 
    alert(child.outerHTML); 
    // this only works if you know there is only one 
    // child element, though 
}); 
0

首先,你需要知道的是類屬性是後點確定它在你的情況下,你的類名 .quote_content那麼你必須去的子元素,我知道2種方法來做到這一點。

1-

$('.quote_content > a') 

2-

$('.quote_content').children("a") 

,或者如果子元素有一個類:

1-

$('.quote_content > .child_element_class') 

2-

$('.quote_content').children(".child_element_class") 
0
function showCompare() { 
    var quote_content = document.getElementById('quote_content'); 
    console.log(quote_content); 
    win = new Window({className: "mac_os_x", title: "Sample", width:800, height:400, destroyOnClose: true, recenterAuto:false}); 

    win.getContent().innerHTML = quote_content.innerHTML; 
    win.showCenter(); 
}