[英]how to innerHTML a content of pre tag
Hi I have a FTP site on my browser like ftp://ftp.bom.gov.au/anon/gen/clim_data/IDCKWCDEA0/tables/stations_db.txt 嗨,我的浏览器上有一个FTP站点,例如ftp://ftp.bom.gov.au/anon/gen/clim_data/IDCKWCDEA0/tables/stations_db.txt
I am trying to get the text inside the pre tag using document.getElementsByTagName('pre').innerHTML it is returning udefined. 我正在尝试使用document.getElementsByTagName('pre')。innerHTML获取pre标签内的文本,它正在返回udefined。 Is someone can tell me why I cannot get the content of the 有人可以告诉我为什么我无法获取内容吗
`<html><head><link rel="alternate stylesheet" type="text/css" href="resource://gre-resources/plaintext.css" title="Wrap Long Lines"></head><body><pre>015590 NT 15B ALICE SPRINGS AIRPORT 19400101.. -23.7951 133.889
014272 NT 14GA BATCHELOR AIRPORT 19920813.. -13.0545 131.0252
014723 NT 14DE BORROLOOLA AIRPORT 19871107.. -16.0755 136.3041
014954 NT 14GA BRADSHAW 19980529.. -14.9408 130.8092
014627 NT 14DE BULMAN 20021010.. -13.6714 134.3414
014909 NT 14GA CENTRAL ARNHEM PLATEAU 20030731.. -13.3275 133.0861
014703 NT 14DE CENTRE ISLAND 19680101..
</pre>
</body>
</html>`
document.getElementsByTagName
returns an array, not a single element. document.getElementsByTagName
返回一个数组,而不是单个元素。 You need to specify which element of the fetched elements you want to modify. 您需要在获取的元素中指定要修改的元素。 Try with 试试看
document.getElementsByTagName('pre')[0].innerHTML
Alternatively, a better solution would be to give that pre
an id, so that you can target it precisely (because it might happen, that the pre
won't be the first element fetched as I assumed by using [0]
) 或者,更好的解决方案是给该pre
一个id,以便您可以精确地定位它(因为它可能发生,所以pre
不会是我假设使用[0]
获取的第一个元素)
document.getElementById('pre-element').innerHTML
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.