Благодаря помощи другого пользователя я смог настроить всплывающее окно, которое выглядит великолепно, но я не могу заставить работать onclick, чтобы всплывающее окно не отображалось до тех пор, пока не будет щелкнуть номер телефона. Я хотел бы показать номер телефона отдельно, и после нажатия появится всплывающее окно, которое спросит пользователя: «Позвонить или текст?», А затем пользователь нажимает кнопку по своему выбору. Спасибо!
var modal = document.getElementById('textCall');
var span = document.getElementById("close");
modal.style.display = "block";
span.onclick = function(){
modal.style.display = "none";
}
CSS
.dialogue {
display: none;
position: fixed;
z-index: 1;
padding-top: 150px;
left: 0;
top: 0;
width: 100%;
height: 100%;
overflow: auto;
background-color: rgba(0,0,0,0.4);
}
#close, #closed {
color: #aaaaaa;
float: right;
font-size: 28px;
font-weight: bold;
}
#close:hover,
#close:focus,
#closed:focus,
#closed:hover {
color: #000000;
text-decoration: none;
cursor: pointer;
}
.modal-content {
background-color: #fefefe;
margin: auto;
padding: 20px;
border: 1px solid #888;
width: 40%;
}
#textCall {
display: block;
}
HTML
<p onclick = "textCall">555-5555</p>
<div id = "textCall" class = "dialogue">
<div class = "modal-content">
<span id = "close">×</span>
<h2>Call or Text?</h2>
<a href = "tel:15555555555">Call</a>
<a href = "sms:15555555555">Text</a>
</div>
</div>
</div>



![Безумие обратных вызовов в javascript [JS]](https://i.imgur.com/WsjO6zJb.png)


Эта функция - то, что вы ищете:
function textCall(e) {
modal.style.display = "block";
}
Проверьте фрагмент:
var modal = document.getElementById('textCall');
var span = document.getElementById("close");
var number = document.getElementById("number");
number.onclick = function() {
modal.style.display = "block";
};
span.onclick = function() {
modal.style.display = "none";
};
var modal = document.getElementById('textCall');
var span = document.getElementById("close");
span.onclick = function() {
modal.style.display = "none";
};
function textCall(e) {
modal.style.display = "block";
}.dialogue {
display: none;
position: fixed;
z-index: 1;
padding-top: 150px;
left: 0;
top: 0;
width: 100%;
height: 100%;
overflow: auto;
background-color: rgba(0,0,0,0.4);
}
#number {
cursor: pointer;
}
#close, #closed {
color: #aaaaaa;
float: right;
font-size: 28px;
font-weight: bold;
}
#close:hover,
#close:focus,
#closed:focus,
#closed:hover {
color: #000000;
text-decoration: none;
cursor: pointer;
}
.modal-content {
background-color: #fefefe;
margin: auto;
padding: 20px;
border: 1px solid #888;
width: 40%;
}<p id = "number" onclick = "textCall()">555-5555</p>
<div id = "textCall" class = "dialogue">
<div class = "modal-content">
<span id = "close">×</span>
<h2>Call or Text?</h2>
<a href = "tel:15555555555">Call</a>
<a href = "sms:15555555555">Text</a>
</div>
</div>Это отлично работает для onclick, но он все еще загружает всплывающее окно при загрузке страницы. Есть ли способ, чтобы всплывающее окно не загружалось, пока не будет нажата цифра? Большое спасибо за Вашу помощь!
@SweetBabyJames Я отредактировал вопрос, чтобы он работал так, как вы ожидали. Попробуйте, пожалуйста.
Спасибо за помощь. Всплывающее окно не запускалось при загрузке страницы, но теперь всплывающее окно исчезает при нажатии.
Для этого вам необходимо изначально установить display:'none' в модальное окно. Вы можете сделать onclick функцией для своих элементов и сделать show или hide своим модальным окном вот так.
ДЕМО
function closeModal(e) {
document.getElementById('textCall').style.display = "none";
}
function textCall(e) {
document.getElementById('textCall').style.display = "block";
}.dialogue {
display: none;
position: fixed;
z-index: 1;
left: 0;
top: 0;
width: 100%;
height: 100%;
overflow: auto;
background-color: rgba(0, 0, 0, 0.4);
}
.number {
cursor: pointer;
}
#close,
#closed {
color: #aaaaaa;
float: right;
font-size: 28px;
font-weight: bold;
}
#close:hover,
#close:focus,
#closed:focus,
#closed:hover {
color: #000000;
text-decoration: none;
cursor: pointer;
}
.modal-content {
background-color: #fefefe;
margin: auto;
padding: 20px;
border: 1px solid #888;
width: 40%;
position: fixed;
top: 25%;
left: 25%
}<p class = "number" onclick = "textCall(this)">555-5555</p>
<div id = "textCall" class = "dialogue">
<div class = "modal-content">
<span onclick = "closeModal(this)" id = "close">×</span>
<h2>Call or Text?</h2>
<a href = "tel:15555555555">Call</a>
<a href = "sms:15555555555">Text</a>
</div>
</div>