我分别测试和调试了警报的代码与我网站的其余部分,当它分开时它可以完美运行,但是当我将代码放入我的网站时,警报将不起作用。
测试网站的代码显示一个警报,说"这个网站有假新闻",但实际网站没有显示任何内容。
我尝试手动调试代码,尝试使用Visual Studio Code的调试器调试代码,我让我的朋友查看代码,没有人可以在代码中找到错误。
以下是网站的一些警报代码:
<div class="popup">The Earth Is Flat
<span class="popuptext" id="myPopup"><img src="images/fi.jpg">
<b>ALERT!</b><br>The Blank Device has scanned this website and found Fake News. The phrase "The Earth is flat." is Fake News.</span>
</div>
这是它工作的测试网站中的警报代码:
<div class="popup">The Earth Is Flat
<span class="popuptext" id="myPopup"><img src="images/fi.jpg">
<b>ALERT!</b><br>The Blank Device has scanned this website and found Fake News. The phrase "The Earth is flat." is Fake News.</span>
</div>
这是两个网站中的JavaScript代码:
function myFunction() {
var popup = document.getElementById("myPopup");
setTimeout(function(){ popup.classList.toggle("show");}, 3000);
}
这是 CSS:
position: relative;
display: inline-block;
cursor: pointer;
-webkit-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
}
/* The actual popup */
.popup .popuptext {
visibility: hidden;
width: 160px;
background-color: #FF0000;
color: #fff;
text-align: center;
border-radius: 6px;
padding: 8px 0;
position: absolute;
z-index: 1;
bottom: 125%;
left: 50%;
margin-left: -80px;
}
/* Popup arrow */
.popup .popuptext::after {
content: "";
position: absolute;
top: 100%;
left: 50%;
margin-left: -5px;
border-width: 5px;
border-style: solid;
border-color: #FF0000 transparent transparent transparent;
}
/* Toggle this class - hide and show the popup */
.popup .show {
visibility: visible;
-webkit-animation: fadeIn 1s;
animation: fadeIn 1s;
}
/* Add animation (fade in the popup) */
@-webkit-keyframes fadeIn {
from {opacity: 0;}
to {opacity: 1;}
}
@keyframes fadeIn {
from {opacity: 0;}
to {opacity:1 ;}
}
测试网站的代码显示一个警报,说"这个网站有假新闻",但实际网站没有显示任何内容。
你试过这个吗?从逻辑上讲它会起作用
<body onload="myFunction()">
<div class="popup">The Earth Is Flat
<span class="popuptext" id="myPopup"><img src="images/fi.jpg">
<b>ALERT!</b><br>The Blank Device has scanned this website and found Fake News. The phrase "The Earth is flat." is Fake News.</span>
</div>
<div class="popup">The Earth Is Flat
<span class="popuptext" id="myPopup"><img src="images/fi.jpg">
<b>ALERT!</b><br>The Blank Device has scanned this website and found Fake News. The phrase "The Earth is flat." is Fake News.</span>
</div>
</body>
您是否忘记在正文标签中输入 js 函数?