打印javascript开关语句到HTML页面
print javascript switch statement to html page
对不起,如果我解释这个错误,我是非常新的javascript。我试图打印这个开关语句到我的html页面,我不知道如何做到这一点。如有任何帮助,我将不胜感激。
在我的HTML页面我有:
<button type="button" onclick="weatherAssessment()">Weather Assassment</button>
<p id="result"> <p>
我只是不确定如何使用getElementbyID将结果打印到页面。
JavaScript:function weatherAssessment(){
var currentDate = new Date();
var currentMonth = currentDate.getMonth();
switch(currentMonth) {
case 11:
case 0:
case 1:
analysis = "It is chilly winter.";
break;
case 2:
case 3:
case 4:
analysis = "A beautiful spring.";
break;
case 5:
case 6:
case 7:
analysis = "The heat of summer.";
break;
case 8:
case 9:
case 10:
analysis = "Fabulous Fall";
break;
}
console.log(currentMonth);
console.log(analysis);
}
试试这个…
<html>
<head>
</head>
<body>
<button type="button" onclick="weatherAssessment()">Weather Assassment</button>
<p id="result"> <p>
</body>
</html>
<script>
function weatherAssessment(){
var currentDate = new Date();
var currentMonth = currentDate.getMonth();
switch(currentMonth) {
case 11:
case 0:
case 1:
analysis = "It is chilly winter.";
break;
case 2:
case 3:
case 4:
analysis = "A beautiful spring.";
break;
case 5:
case 6:
case 7:
analysis = "The heat of summer.";
break;
case 8:
case 9:
case 10:
analysis = "Fabulous Fall";
break;
}
// console.log(currentMonth);
// console.log(analysis);
document.getElementById("result").innerHTML = "Current Month: " + currentMonth + " Analysis: " + analysis;
}
</script>
直接使用:
document.getElementById("result").innerHTML = "yourText";
相关文章:
- 使用javascript将动态表从一个html页面打印到另一个html页
- 在chrome.tabs.onCreated之后加载HTML页面
- 如何在vs2002中调试html页面
- 使用angular重定向到html页面
- Html页面上的多个Base64图像和平滑加载
- 无法将数据从firebase获取到我的html页面
- 如何在chrome扩展中重定向到html页面
- 如何将值传递到上一个html页面
- AngularJS-需要在index.html页面中访问来自服务的数据
- 如何使用Node/Express显示有关特定错误的自定义html页面
- 如何在 html 页面中调用 jquery
- 加载存储在IndexedDB中的HTML页面
- 同一HTML页面中的两个不同版本的JQuery
- HTML页面如何提取通过表单传递的参数
- 在HTML页面上将URL解析为可读的json格式
- 使用jQuery插入HTML页面的第一个项目缺少结束标记
- 在HTML页面上显示node.js服务器中的数据
- 加载页面时更改html页面的位置
- Ajax调用返回当前html页面,而不是请求的文件
- css是从远程node.js添加的,但不适用于html页面