javascript - 如何使用 javascript 更改 figcaption 的内容?
问题描述
<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 但它们似乎都不起作用。有小费吗?
解决方案
所以我发现我的代码有什么问题。而不是使用“使用”来代替它。EG
<script>
function changefigure()
{
var x = document.getElementById("Image");
var y = document.getElementById("caption")
x.src = 'NT_Naplan_Reading_Results_2011.png'
y.innerHTML = '<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>
推荐阅读
- ios - Do 和 Map 有什么区别?
- ruby - Ruby unix 套接字客户端和服务器示例
- c - realloc():将项目附加到数组时下一个大小无效
- python - 如何在不保存或使用 ORM 的情况下上传多个 csv
- c# - 如何在 C# 中从数据库中检索 KeyValuePair 的值?
- android-studio - 如何在 Android Studio 的 gradle build 中启用 --stacktrace 或 --info 或 --debug 或 --scan 选项?
- laravel - 如何在根据日期和时间过滤的同时进行验证?
- laravel - 拉取时重复 db 表中的数据
- javascript - 如何在单击时显示 Mailchimp 订阅弹出表单
- apigee - lookupcache.LookupCachePolicy.cachehit 在请求中显示 true 或 false