Я создал сайт, который работает точно так же, как и в Chrome, но не работает в IE11.При нажатии кнопки над кнопкой должно появиться всплывающее окно с текстом из HTML (это прекрасно работает в Chrome)
При работе в IE11 я получаю эту ошибку:
SCRIPT5007:Невозможно получить свойство 'toggle' с неопределенной или нулевой ссылкой
script.js (3,3)
Это указывает на мой файл js (называемый script.js):
function myFunction(data) {
var popup = document.getElementById("myPopup"+data);
popup.classList.toggle("show");
}
Ошибка появляется, когда я нажимаю кнопку для просмотра всплывающего окна, функция вызывается только при нажатии кнопки.
Есть ли способ заставить это работать и в IE11?as Chrome?
Ниже приведен фрагмент о том, как всплывающее окно должно работать в IE11.
function myFunction(data) {
var popup = document.getElementById("myPopup" + data);
popup.classList.toggle("show");
}
/* Popup container */
.popup {
position: relative;
display: inline-block;
cursor: pointer;
width: 100%;
padding-top: 15px;
padding-bottom: 15px;
background: white;
border: none;
font-size: 25px;
}
.popup:hover {
background-color: #008CBA;
color: white;
}
/* The actual popup (appears on top) */
.popup .popuptext {
visibility: hidden;
width: 250px;
background-color: #555;
color: #fff;
text-align: center;
border-radius: 6px;
padding: 8px 0;
position: absolute;
z-index: 1;
bottom: 110%;
left: 30%;
margin-left: -80px;
font-size: 16px;
}
/* Popup arrow */
.popup .popuptext::after {
content: "";
position: absolute;
top: 100%;
left: 50%;
margin-left: -5px;
border-width: 5px;
border-style: solid;
border-color: #555 transparent transparent transparent;
}
/* Toggle this class when clicking on the popup container (hide and show the popup) */
.popup .show {
visibility: visible;
-webkit-animation: fadeIn 1s;
-moz-animation: fadeIn 1s;
-ms-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;
}
}
<!DOCTYPE html>
<html>
<head>
<link href="style.css" rel="stylesheet">
<script type="text/javascript" src="script.js"></script>
</head>
<body>
<table>
<tr>
<th colspan="4">Test Buttons</th>
</tr>
<tr>
<td><button class="popup" onclick="myFunction(1)">1<span class="popuptext" id="myPopup1">Test Button 1</span></button></td>
<td><button class="popup" onclick="myFunction(2)">2<span class="popuptext" id="myPopup2">Test Button 2</span></button></td>
<td><button class="popup" onclick="myFunction(3)">3<span class="popuptext" id="myPopup3">Test Button 3</span></button></td>
<td><button class="popup" onclick="myFunction(4)">4<span class="popuptext" id="myPopup4">Test Button 4</span></button></td>
</tr>
</table>
</body>
</html>