2013-03-06 139 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)