使用jQuery获取外部DIV的文本 [英] Getting a text of Outer DIV using Jquery
本文介绍了使用jQuery获取外部DIV的文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有这样的外DIVS.
I have Outer DIVS like this.
<Input id ="SaveMe" value="Click" type="submit" >
</Input>
<DIV id="DivOne">
<DIV >First Content
<DIV>X
</DIV>
</DIV>
<DIV>Second Content
<DIV>X
</DIV>
</DIV>
</DIV>
我想遍历外部DIV并获取文本.我正在使用JQuery代码.
I would like to loop through outer DIVs and get the text.I am using the JQuery Code.
$("#SaveMe").click(function() {
$("#DivOne").children().each(function(index, elem) {
alert($(elem).text());
});
});
但是它显示了第一个内容X,第二个内容X.我希望每个循环"先循环通过外部DIV,然后再循环通过内部DIV.我如何忽略通过内部DIV循环(具有内容X的DIV) ). http://jsfiddle.net/VVGRc/1/
But it shows First Content X ,Second Content X. I was hoping the "each loop" will loop through the outer DIV first and then the inner DIVs.How can i ignore looping through the inner DIVs (the DIVs with content X). http://jsfiddle.net/VVGRc/1/
谢谢!
推荐答案
男性为克隆人.删除克隆的所有child.elements.返回文字内容
Male a clone. Delete all child.elements of the clone. Return the text content
这篇关于使用jQuery获取外部DIV的文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文