私はボタンを押して、私が望む内容のポップアップを表示する機能を持っています。あなたはこれを以下で見ることができます。私はこれらの複数を持っているが、コードを変更する方法がわからない。別のポップアップの内容を開くボタンを用意したいと思います。他のボタンにポップアップを適用します。 1つのボタンに対応するコードを持っています
JSコードをコピーして貼り付けて関連IDを変更しましたが、動作しません。誰にでもアイデアはありますか?
ありがとうございます! osyan同様
// Get the modal
var modal = document.getElementById('myModal');
// Get the button that opens the modal
var btn = document.getElementById("myBtn");
// Get the <span> element that closes the modal
var span = document.getElementsByClassName("close")[0];
// When the user clicks the button, open the modal
btn.onclick = 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";
}
}
HTML (Button):
<button class="buttin" id="myBtn">Terms & Conditions</button>
HTML (Pop Up Content):
<div id="myModal" class="modal">
<!-- Modal content -->
<div class="modal-content">
<span class="close">×</span>
<h3 style="margin-top: 0px;"><strong>Terms and Conditions</strong></h3>
Please read the following terms and conditions before using our website.
</div>
</div>
複数のPOP-UPSの複数のIDを使用して、複数の時間それらを呼び出します! – osyan
JSコードでありがとうございます。それはこのようなものでしょうか? var modal = document.getElementById( 'myModal'。 'myModal1'); とし、HTMLでIDを変更しましたか? – Phil
'var modal = document.getElementById( 'myModal1');' 'id =" myModal1 "'を使用してください – osyan