我是JS的新手。页面加载时,以下JS代码不起作用。
function alert10() {
var today = new Date().getMinutes();
if (today > 10) {
window.onload = function() {
document.getElementById('timer10').style.display = 'none';
};
}
}
我正在如下调用alert10():
<header onload="alert10()">
以下是我要隐藏的元素:
<h5 id="timer10" style=" position:absolute;top: 1px;left: 151px;"></h5>
使用window.onload尝试以下操作:
<html>
<body>
<h5 id="timer10" style=" position:absolute;top: 1px;left: 151px;">Something</h5>
<script>
window.onload = () => {
var today = new Date().getMinutes();
if (today > 10) {
document.getElementById('timer10').style.display = 'none';
} else {
alert('minutes is less than 10')
}
}
</script>
</body>
</html>
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句