我在JQuery工作之前,我有点不明白我如何在原型上获得<a>asd</a>
.quote_content
<div class="quote_content">
<a>asd</a>
</div>
谢谢!
更新
我有一个功能:
<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]
答案 0 :(得分:2)
试试这个,如果您只想查看任何带有classname 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
});
答案 1 :(得分:0)
首先你需要知道的是class属性是用类名后面的一个点来识别它,
在你的情况下.quote_content
然后你必须选择子元素,我知道两种方法。
1 -
$('.quote_content > a')
2 -
$('.quote_content').children("a")
或者如果子元素有一个类:
1 -
$('.quote_content > .child_element_class')
2 -
$('.quote_content').children(".child_element_class")
答案 2 :(得分: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();
}