Javascript 元素witout和元素的内部文本

Javascript 元素witout和元素的内部文本,javascript,Javascript,我有以下代码: <span class="start-end"> <duration>October </duration> – December (1 duration) </span> 对于第一个代码块的2010年10月,对于第二个代码块的2010年9月 如何从第一块12月(1个持续时间) 从第二个块开始,使用另一个命令执行2014年6月的(2个持续时间)(2个持续时间)是.start-end span的文本。我会用 document.que

我有以下代码:

<span class="start-end">
<duration>October </duration>
– December (1 duration)
</span>
对于第一个代码块的
2010年10月
,对于第二个代码块的
2010年9月

如何从第一块
12月(1个持续时间)
从第二个块开始,使用另一个命令执行2014年6月的
(2个持续时间)
(2个持续时间)是.start-end span的文本。我会用

document.querySelector(span.start-end).textContent;
(2 duration)是.start-end跨度的文本。我会用

document.querySelector(span.start-end).textContent;
您可以使用获取任何子元素(或在本例中为最后一个子元素):

您可以使用获取任何子元素(或在本例中为最后一个子元素):

var span=document.getElementsByClassName(“开始-结束”)
用于(跨距中的var k){
var span=跨度[k]
var durations=span.getElementsByTagName(“持续时间”)
if(durations.length==1){
console.log(持续时间[0].innerHTML)
}else if(durations.length==2){
console.log(持续时间[0]。innerHTML,持续时间[1]。innerHTML)
}
}

十月
–12月(1个持续时间)
还有一个:
2010年9月
–
2014年6月
(2)持续时间
var span=document.getElementsByClassName(“开始-结束”)
用于(跨距中的var k){
var span=跨度[k]
var durations=span.getElementsByTagName(“持续时间”)
if(durations.length==1){
console.log(持续时间[0].innerHTML)
}else if(durations.length==2){
console.log(持续时间[0]。innerHTML,持续时间[1]。innerHTML)
}
}

十月
–12月(1个持续时间)
还有一个:
2010年9月
–
2014年6月
(2)持续时间
document.querySelector(span.start-end).textContent;
document.querySelector('span.start-end duration:nth-child(2)').innerHTML