我目前正在完成Web开发课程,本周我们将介绍:将Javascript添加到您的网站。这些脚本很容易添加,并且我已经可以使用所有内容,但是,脚本的目的和站点并不一致。任务之一是添加一个按钮,然后单击onclick-显示时间和数据。我打算在这里说明您可以将这些元素添加到页面中-但是对我而言这没有意义。因此,我想以适合我网站目的的方式添加日期和时间-该内容涵盖了COVID信息。因此,我将放在一起的是一个按钮,单击该按钮将显示日期和时间(根据需要),并显示“数据中的世界”中的嵌入地图。
现在,我发现div标签不能有两个ID,而一个函数不能有多个元素。但是,必须有一种方法,使按钮在单击时可以显示两件事-对吗?
因此,在此待了两天之后,这就是我的位置,欢迎您提出任何建议。请记住,我正在这里学习,并且目前我没有接受过Java语言方面的教育。
我在哪里有两个单独的按钮:
<div class="row">
<div class="header">
<h1>Covid Status</h1><br>
<p>The following Button will display what the current COVID Status is around the world, according to Our World In Data.</p><br>
<div id="Covid_stat"></div>
<input type="button" value="Show Chart" onClick="covid();">
<div id="Time"></div>
<input type="button" value="Show Time" onClick="time();">
</div>
</div>
<script>
function Time() {
document.getElementById('time').innerHTML = Date();
}
function Covid_stat(){
document.getElementById('covid').innerHTML='<embed src="https://ourworldindata.org/grapher/positive-rate-daily-smoothed?year=latest&time=earliest..latest" loading="lazy" style="width: 100%; height: 600px; border: 0px none;"></embed>';
}
</script>
我正在尝试通过各种在线示例进行的操作:
<div class="row">
<div class="header">
<h1>Covid Status</h1><br>
<p>The following Button will display what the current COVID Status is around the world, according to Our World In Data.</p><br>
<button type="button" id="Show_Info">Show Information</button>
</div>
</div>
<script>
function Time() {
document.getElementById('time').innerHTML = Date();
}
function Covid_stat(){
document.getElementById('covid').innerHTML='<embed src="https://ourworldindata.org/grapher/positive-rate-daily-smoothed?year=latest&time=earliest..latest" loading="lazy" style="width: 100%; height: 600px; border: 0px none;"></embed>';
}
var showbtn = document.getElementById("Show_Info");
showbtn.addEventListener("click", Time);
showbtn.addEventListener("click", Covid_stat);
</script>
提前,非常感谢!
希望对您有所帮助。
function myFunc() {
document.getElementById('time').innerHTML = Date();
document.getElementById('covid').innerHTML = '<iframe src="https://ourworldindata.org/grapher/positive-rate-daily-smoothed?year=latest&time=earliest..latest" loading="lazy" style="width: 100%; height: 600px; border: 0px none;"></iframe>';
}
var showbtn = document.getElementById("Show_Info");
showbtn.addEventListener("click", myFunc);
<div class="row">
<div class="header">
<h1>Covid Status</h1><br>
<p>The following Button will display what the current COVID Status is around the world, according to Our
World In Data.</p><br>
<button type="button" id="Show_Info">Show Information</button>
</div>
<div id="time"></div>
<div id="covid"></div>
</div>
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句