2013-03-06 155 views
1

如何获取div class =“dpBibHoldingStatement”的内容? 它不能与getElementByClass一起使用,因为html中有几个相同的类。我无法显示所有的代码。获取Div类内容html

<div class="dpBibTitle"> 
    <!-- please read c1063106, c1063117, c1044421, c1060576a before changing title --> 
    <a id="recordDisplayLink2Component_0" href="/iii/encore/record/C__Rb4101617__Sapple__P0%2C1__Orightresult__X5?lang=eng&amp;suite=pearl"> 
          The Apple experience : the secrets of delivering insanely great customer service</a> 
         /by Carmine Gallo 
</div> 
<div class="dpBibAuthor"> 
<!-- author --> 
    <a id="authorDisplayLinkComponent_0" href="/iii/encore/search/C__SGallo%2C+Carmine.__Orightresult?lang=eng&amp;suite=pearl"> 
         Gallo, Carmine.</a> 
</div> 
<div class="dpBibHoldingStatement"> 
    Circulation Collection&nbsp; 
    HF5415.5 .G356 2012 &nbsp; 
    DUE 10-03-13OFF CAMPUS&nbsp; 
    &nbsp; 
</div> 

回答

4

给这个DIV ID和使用innerHTML

<div id="yourDiv"> 
    Content 
</div> 

然后使用JavaScript做:

var contents = document.getElementById("yourDiv").innerHTML; 
alert(contents); 
+0

放在console.log中,所以他可以在webkit检查器中正确读取内容 – theshadowmonkey 2013-03-06 18:51:32

0

首先,它不是getElementByClass。这是getElementsByClassName

当您在此页的开发人员工具上运行document.getElementsByClassName("label-key")时,它会显示一组label-key项。你可以从该数组中获得你想要的任何项目。

0

您可以使用document.getElementsByClassName[n]来定位页面上的第(n-1)个元素,或者为其添加一个ID并使用document.getElementById(id)