【发布时间】:2020-12-21 04:20:27
【问题描述】:
<button onclick="changefigure()">2011</button>
<figure>
<img id="Image" src="NT_Naplan_Reading_Results_2017.png"/>
<figcaption id="caption"><em>Fig 2</em>Percent of children above national minimum standard in
reading in 2017 for Year 3, 5, 7 and 9 for Non-Indigenous and Indigenous children in the
Northern Territory. Data Source <a href="">NAPLAN results</a></figcaption>
</figure>
<script>
function changefigure()
{
var x = document.getElementById("Image");
var y = document.getElementById("caption")
x.src = 'NT_Naplan_Reading_Results_2011.png'
//y = "<em>Fig 1</em>Percent of children above national minimum standard in reading in
2017 for Year 3, 5, 7 and 9 for Non-Indigenous and Indigenous children in the Northern
Territory. Data Source <a href="">NAPLAN results</a>"
}
</script>
所以我似乎无法更改 figcaption。我试过使用 y.innerHTML 和 y.innertext 但它们似乎都不起作用。有什么建议吗?
【问题讨论】:
-
您遇到的具体问题是什么?您是否在控制台中收到任何错误?请向我们展示您用于在 JS 中设置 figcaption 的代码,以便我们查看可能导致问题的原因。
-
它应该可以工作。可能是您有语法错误,因为您以错误的方式构建新字符串。将多行字符串放在两个 ` 字符内。
标签: javascript html