我的弹出广告上有 2 个按钮,根据他们选择的内容,会执行完全不同的操作。然而,它们似乎不适用于移动设备。我想不出替代方案。另外,我希望在操作前延迟大约 2 秒,但我不确定在这种情况下如何使用超时。我厌倦了使用 onkeyup,但这不起作用,onclick 也不起作用。
<div class="modal-content">
<span class="close">×</span>
<div class="radcen">
<input type="radio" id="yes" value="Yes" onchange="window.location.href = 'https://www.example.com/';"><label class="free-label four col" for="yes">Yes</label>
<input type="radio"id="no" value="No" onchange="myModal.style.display = 'none'"><label class="basic-label four col" for="no">No</label>
</div>
</div><!-- Modal content -->
和脚本
var modal = document.getElementById("myModal");
// Get the <span> element that closes the modal
var span = document.getElementsByClassName("close")[0];
// When page loads display pop up
window.onload = function() {
modal.style.display = "block";
}
// When the user clicks on <span> (x), close the modal
span.onclick = function() {
modal.style.display = "none";
}
// When the user clicks anywhere outside of the modal, close it
window.onclick = function(event) {
if (event.target == modal) {
modal.style.display = "none";
}
<!DOCTYPE html>
<html>
<body>
<div class="radcen">
<input type="radio" name="maincov" id="yes" value="Yes"><label class="free-label four col" for="yes">Yes</label>
<input type="radio" name="maincov" id="no" value="No"><label class="basic-label four col" for="no">No</label>
</div>
<div id="myModal" class="modal">
mod content
</div>
<script>
var modal = document.getElementById("myModal");
document.getElementById("yes").addEventListener("change", yes);
document.getElementById("no").addEventListener("change", no);
function no() {
modal.style.display = "none";
}
function yes() {
window.location.href = 'https://www.example.com/';
}
</script>
</body>
</html>