如何读取跨度值

时间:2017-10-19 08:21:24

标签: javascript html

我想读一个html跨度的值。 我怎么能这样做?

这是代码:



//this works
spanRight= document.getElementsByClassName("spanRight")

//but i cant get the text
spanRight = spanRight.text;

<span class="spanRight">1234567890</span>
&#13;
&#13;
&#13;

谢谢你的帮助

2 个答案:

答案 0 :(得分:1)

您可以使用innerText

spanRight = spanRight.innerText;

还有innerHTML可以使用HTML标记返回。 Differences are listed here

答案 1 :(得分:0)

像这样使用ServiceSettings serviceSettings = gson.fromJson(fileContent, ServiceSettings.class); String baseUrl = serviceSettings.getUrl(); RestTemplate restTemplate = new RestTemplate(); String result = restTemplate.postForObject(baseUrl, serviceSettings.getItems(), String.class); //Assuming there is a getter for items 示例:

textContent
spanRight= document.getElementsByClassName("spanRight")

//but i cant get the text
text = spanRight[0].textContent

alert(text);