美好的一天每个人我都有一个工作我的加载只有一次麻烦。因为当我刷新页面或如果我要去另一个页面它总是加载。 这里是到目前为止我的代码:加载需要只工作一次
JS
<!--Auto load the on overlay function-->
<script>
window.onload = function openNav() {
document.getElementById("myNav").style.width = "100%";
splashScreen();
}
function closeNav() {
document.getElementById("myNav").style.width = "0%";
}
</script>
,这里是我的js功能为我splashscreen.js
//use onload when in your html the context is not inside
//the <header>
//create a splashScreen function
function splashScreen(){
//get the element on the html side with the id of "skip"
var skipButton = document.getElementById("skip");
//counter for the countdown
var counter = 5;
//create an element <p>
var newElement = document.createElement("p");
newElement.innerHTML = "Skip this 5 seconds";
var id;
skipButton.parentNode.replaceChild(newElement, skipButton);
id = setInterval(function(){
counter--;
if(counter < 0){
//replace the newElement on else condition statement
newElement.parentNode.replaceChild(skipButton, newElement);
clearInterval(id);
} else {
newElement.innerHTML = "You can skip this in " + counter.toString() + " seconds.";
}
}, 1000);
}
,这是我怎么称呼它在我的html
<html>
<body>
<!--SplashScreen JS-->
<script src="<?php echo base_url('assets/public/js/splashscreen.js');?>">
</script>
我这样做了'''const NAME =“once”; window.onload = function openNav(){ document.getElementById(“myNav”)。style.width =“100%”;如果(this.NAME!== NAME){ splashScreen(); } else { alert(this.name); }我的导航栏上有''' –
我有画廊,当我去我们团队时,我们的团队仍然弹出 –
'this.NAME'与'window'的'name'属性不一样。查看更新后的帖子 – guest271314