javascript - 如何使用 javascript 函数的输出在 HTML 中显示
问题描述
我正在制作一个模拟网站来练习使用 HTML、CSS 和 javascript。我希望用户能够单击将出现叠加层的图像,并在屏幕上显示约会日期。当我尝试显示函数的输出时,什么也没有发生。
我尝试调用函数、特定的输出变量以及“Date.prototype.getNextWeekDate”本身。
<script>
Date.prototype.getNextWeekDay = function(d) {
if (d) {
var next = this;
next.setDate(this.getDate() - this.getDay() + 7 + d);
return next;
}
}
var now = new Date();
var nextMonday = now.getNextWeekDay(1); // 0 = Sunday, 1 = Monday, ...
return nextMonday;
</script>
<style>
#overlay {
position: fixed;
display: none;
width: 100%;
height: 100%;
top: 0;
left: 0;
right: 0;
bottom: 0;
background-color: rgba(0,0,0,0.5);
z-index: 2;
cursor: pointer;
}
#text{
position: absolute;
top: 50%;
left: 50%;
font-size: 50px;
color: white;
transform: translate(-50%,-50%);
-ms-transform: translate(-50%,-50%);
}
</style>
<div id="overlay" onclick="off()">
<div id="text">
<p>Your appointment is at:<script>fucntion(d);</script></p>
</div>
</div>
<script>
function on() {
document.getElementById("overlay").style.display = "block";
}
function off() {
document.getElementById("overlay").style.display = "none";
}
</script>
<img src="images/m&R_Idk.jpg" width="500" height="298" alt="Mechanic Appointment"
onClick="on()" >
7 天内的当前日期应输出到叠加层上,但根本没有输出。
解决方案
推荐阅读
- python - 在 youtube 下载器 kivy 应用程序中没有响应
- flutter - 使用来自 firebase 实时数据库的 json 数据填充 firestore 数据库
- mongodb - MongoDB - 根据前一项计算字段
- javascript - 我们如何将文本与 PayPal 字段变量连接起来?
- ios - 如何防止 ScrollView 自动显示在内部 ForEach 顶部添加的项目
- php - 在 WooCommerce 的单个产品页面上隐藏某些产品的产品库存
- r - rJava 在 shell 中加载和执行,但不在 cron 中
- android - Flutter项目添加华为agconnect后构建失败
- react-native - React Native)在字符串中连接变量(或JSX元素)
- java - 在spring-weblux中使用WebClient发送请求时如何从reactor netty管道中删除HttpClientCodec处理程序(默认添加)