[英]Get Div class content html
我怎样才能获得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&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&suite=pearl">
Gallo, Carmine.</a>
</div>
<div class="dpBibHoldingStatement">
Circulation Collection
HF5415.5 .G356 2012
DUE 10-03-13OFF CAMPUS
</div>
给div一个ID并使用innerHTML
:
<div id="yourDiv">
Content
</div>
然后使用JavaScript执行:
var contents = document.getElementById("yourDiv").innerHTML;
alert(contents);
首先,它不是getElementByClass
。 它是getElementsByClassName
。
当您在开发人员工具的此页面上运行document.getElementsByClassName("label-key")
时,它将显示一系列label-key
项。 您可以从该阵列中获取所需的任何项目。
您可以使用document.getElementsByClassName[n]
来定位页面上的第(n-1)个元素,或者为其附加一个ID并使用document.getElementById(id)
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.