gpt4 book ai didi

javascript - 当我将警报代码与我网站的其余代码结合使用时,我的警报代码将不起作用

转载 作者:行者123 更新时间:2023-11-27 23:42:11 25 4
gpt4 key购买 nike

我测试和调试了与我网站的其余部分分开的警报代码,当它分开时它可以完美地工作,但是当我将代码放入我的网站时,警报将不起作用。

测试网站的代码会显示一条警告“该网站有假新闻”,但实际网站没有显示任何内容。

我试过手动调试代码,我试过使用visual studio code的调试器调试代码,我让我的 friend 看代码,没有人能发现代码中的错误。

这是该网站的一些警报代码:

    <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>

你是不是忘了在你的 body 标签中包含 js 函数?

关于javascript - 当我将警报代码与我网站的其余代码结合使用时,我的警报代码将不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56980335/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com