简体   繁体   English

获取Div类内容html

[英]Get Div class content html

How can I get content of div class="dpBibHoldingStatement" ? 我怎样才能获得div class =“dpBibHoldingStatement”的内容? It can't be used with getElementByClass, because there are several same classes in the html. 它不能与getElementByClass一起使用,因为html中有几个相同的类。 I can't show all the code. 我无法显示所有代码。

<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>

Give the div an ID and use innerHTML : 给div一个ID并使用innerHTML

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

Then using JavaScript do: 然后使用JavaScript执行:

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

First of all, it's not getElementByClass . 首先,它不是getElementByClass It's getElementsByClassName . 它是getElementsByClassName

When you run document.getElementsByClassName("label-key") on this page at developer tools, it'll show you an array of label-key items. 当您在开发人员工具的此页面上运行document.getElementsByClassName("label-key")时,它将显示一系列label-key项。 You can get any item that you want from that array. 您可以从该阵列中获取所需的任何项目。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM