1

如何获取 div class="dpBibHoldingStatement" 的内容?它不能与 getElementByClass 一起使用,因为 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

3 回答 3

4

给 div 一个 ID 并使用innerHTML

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

然后使用 JavaScript 做:

 var contents = document.getElementById("yourDiv").innerHTML;
 alert(contents);
于 2013-03-06T18:48:14.720 回答
0

You can either use document.getElementsByClassName[n] to target the (n-1)th element on the page, or you attach an ID to it and use document.getElementById(id).

于 2013-03-06T18:53:21.900 回答
0

首先,它不是getElementByClass。是getElementsByClassName

当您document.getElementsByClassName("label-key")在开发者工具的此页面上运行时,它会向您显示一系列label-key项目。您可以从该数组中获取所需的任何项目。

于 2013-03-06T18:51:36.090 回答