【发布时间】:2024-04-30 04:00:02
【问题描述】:
在页面上,保存按钮应根据系统时间显示或隐藏。 我想每天上午 10 点后隐藏保存按钮。 我的破代码
<script type="text/javascript">
var currentTime = new Date();
var hours = currentTime.getHours();
var newButton = document.getElementById("btn1");
if(hours>10) {
newButton.style.display = "none";
//tried this one too
// document.getElementById('btn1').style.visibility = 'hidden';
}
else {
newButton.style.display = "block";
}
</script>
在我添加的 HTML 代码中
<input id="btn1" type="button" value="Save" name="btnSave" onclick="javascript: {ddwrt:GenFireServerEvent('__commit')}" />
任何建议或帮助。
【问题讨论】:
-
这应该可以。脚本标签是在 HTML 中的元素之前还是之后?
-
另外附注:绕过此代码非常容易,无论是使用开发工具还是调整我的时钟设置。您还应该对服务器端代码实施相同的检查。
-
它位于页面的开头,我也将链接放在了 css 中。以前也是这样。这就是我所说的
-
感谢您对安全性发表评论,但这是一个允许或禁止用户在学生餐厅保存午餐点餐的页面。
-
顺便说一句,要停止按钮工作,请使用
newButton.disabled = true。现在它根本不起作用。
标签: javascript button time hide