2016-02-05 67 views
0

我尝试检索页面上的数据。 我无法更改标记。只有控制台才能使用。选择不是“跨越”的文本

<div class="dataContainer" style="display: block;"> 
<h4>titre</h4> 
<b>Type:</b> Affiliate<br> 
<b>Location:</b> 400 Jackson Boulevard, Los Angeles, CA, 90002<br> 
<b>Phone:</b> (xxx) yyy-zzzz <br> 
<b>Fax:</b> (xxx) yyy-zzzz <br> 
<b>Contact Person:</b> John Doe<br> 
<b>Email Address:</b> <a href="mailto:[email protected]">[email protected]</a><br> 
<b>Website:</b> <a href="http://example.com" target="_blank">http://example.com</a><br> 
<b>Designations:</b> job title 
</div> 

要检索联系人的名字,我想:

var b = jQuery(jQuery('.dataContainer').children('b:contains(Contact)').nextSibling); 
alert(b.text()); 

</b>后如何选择字符串?

回答

5

.children()返回一个jQuery对象,所以叫nextSibling你需要得到的DOM元素引用

var b = jQuery(jQuery('.dataContainer').children('b:contains(Contact)')[0].nextSibling); 
 
alert(b.text());
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> 
 
<div class="dataContainer" style="display: block;"> 
 
    <h4>titre</h4> 
 
    <b>Type:</b> Affiliate 
 
    <br> 
 
    <b>Location:</b> 400 Jackson Boulevard, Los Angeles, CA, 90002 
 
    <br> 
 
    <b>Phone:</b> (xxx) yyy-zzzz 
 
    <br> 
 
    <b>Fax:</b> (xxx) yyy-zzzz 
 
    <br> 
 
    <b>Contact Person:</b> John Doe 
 
    <br> 
 
    <b>Email Address:</b> <a href="mailto:[email protected]">[email protected]</a> 
 
    <br> 
 
    <b>Website:</b> <a href="http://example.com" target="_blank">http://example.com</a> 
 
    <br> 
 
    <b>Designations:</b> job title 
 
</div>

+0

的伟大工程阿伦,THX! 我可以参考的任何文档,以更好地理解jQuery对象的基本概念?我相信_children_是一个jQuery的函数,而_nextSibling_是一个核心的JavaScript方法,所以这[0]与从jQuery到JavaScript的一些_conversion_相关? –

+0

是[0]与get(0)相同吗? –

+0

@AdrienLafond是的..他们是一样的 –