2017-06-17 7 views
2

本質的に私は2つのリンクを持っています。リンク1はポップアップ(ポップアップ1と言う)を開き、リンク2は別のポップアップ(ポップアップ2)を開きます。今のように、どちらもポップアップ2のみを開きます。このコードの正確な内容を変更する必要がありますか? https://jsfiddle.net/mattwalker1092/xxgt4tm5/あるいは、以下:異なるポップアップウィンドウを開く2つのモーダルボタンの作成

コードはここに表示され

body { 
 
\t background: #1f1f2e; } 
 
\t 
 
ppopup { 
 
    color: #000000; 
 
\t font-family: "cambria"; 
 
\t font-size: 22px } \t 
 

 
.modal { 
 
    display: none; /* Hidden by default */ 
 
    position: fixed; /* Stay in place */ 
 
    z-index: 1; /* Sit on top */ 
 
    padding-top: 100px; /* Location of the box */ 
 
    left: 0; 
 
    top: 0; 
 
    width: 100%; /* Full width */ 
 
    height: 100%; /* Full height */ 
 
    overflow: scroll; /* Enable scroll if needed */ 
 
    background-color: rgb(0,0,0); /* Fallback color */ 
 
    background-color: rgba(0,0,0,0.4); /* Black w/ opacity */ } 
 

 
.modal-content { 
 
    background-color: #dbd9d7; 
 
\t text-align: center; 
 
    margin: auto; 
 
    padding: 20px; 
 
    border: 1px solid #888; 
 
    width: 50%; 
 
\t height: 70%; 
 
\t overflow-x: hidden; 
 
\t overflow-y: scroll; } 
 
\t 
 
.close { 
 
    color: #aaaaaa; 
 
    float: right; 
 
    font-size: 28px; 
 
    font-weight: bold; } 
 
.close:hover, 
 
.close:focus { 
 
    color: #000; 
 
    text-decoration: none; 
 
    cursor: pointer; } 
 

 
button { 
 
    background:none!important; 
 
    border:none; 
 
    padding:0!important; 
 
\t 
 
\t color: #cc9966; 
 
\t font-family: "Century Gothic"; 
 
\t font-size: 16px; 
 
\t text-decoration: none;} 
 
\t 
 
.txt:hover { 
 
    text-decoration: underline; }
<!-- Trigger/Open The Modal --> 
 
<center><button id="myBtnONE"><span class="txt" style="cursor:pointer">Link 1</span></button></center> 
 

 
<!-- The Modal --> 
 
<div id="myModalONE" class="modal"> 
 

 
    <!-- Modal content --> 
 
    <div class="modal-content"> 
 
    <span class="close">&times;</span> 
 
    <p><ppopup> 
 
\t This is my FIRST TEST 
 
\t </ppopup></p> 
 
    </div> 
 
</div> 
 

 
<script> 
 
// Get the modal 
 
var modal = document.getElementById('myModalONE'); 
 

 
// Get the button that opens the modal 
 
var btn = document.getElementById("myBtnONE"); 
 

 
var span = document.getElementsByClassName("close")[0]; 
 
btn.onclick = function() { 
 
    modal.style.display = "block"; } 
 
span.onclick = function() { 
 
    modal.style.display = "none"; } 
 
window.onclick = function(event) { 
 
    if (event.target == modal) { 
 
     modal.style.display = "none"; } } 
 
</script> 
 

 

 
<center><button id="myBtnTWO"><span class="txt" style="cursor:pointer">Link 2</span></button></center> 
 

 
<!-- The Modal --> 
 
<div id="myModalTWO" class="modal"> 
 

 
    <!-- Modal content --> 
 
    <div class="modal-content"> 
 
    <span class="close">&times;</span> 
 
    <p><ppopup> 
 
\t \t This is a SECOND TEST 
 
\t </ppopup></p> 
 
    </div> 
 
</div> 
 

 
<script> 
 
// Get the modal 
 
var modal = document.getElementById('myModalTWO'); 
 

 
// Get the button that opens the modal 
 
var btn = document.getElementById("myBtnTWO"); 
 

 
var span = document.getElementsByClassName("close")[0]; 
 
btn.onclick = function() { 
 
    modal.style.display = "block"; } 
 
span.onclick = function() { 
 
    modal.style.display = "none"; } 
 
window.onclick = function(event) { 
 
    if (event.target == modal) { 
 
     modal.style.display = "none"; } } 
 
</script>

答えて

0

https://jsfiddle.net/nf6bcpdu/を参照してください。ちょうど起こることをバインドするためにいくつかのonclickイベントを使用してください。

<center><button id="myBtnONE"><span class="txt" style="cursor:pointer" onclick="OpenModalOne();">Link 1</span></button></center> 

<!-- The Modal --> 
<div id="myModalONE" class="modal"> 

    <!-- Modal content --> 
    <div class="modal-content"> 
    <span class="close" onclick="CloseModalOne();">&times;</span> 
    <p><ppopup> 
    This is my FIRST TEST 
    </ppopup></p> 
    </div> 
</div> 

<script> 

function OpenModalOne() { 
    var modal = document.getElementById('myModalONE'); 
    modal.style.display = "block"; 
} 

function OpenModalTwo() { 
    var modal = document.getElementById('myModalTWO'); 
    modal.style.display = "block"; 
} 

function CloseModalOne() { 
    var modal = document.getElementById('myModalONE'); 
    modal.style.display = "none"; 
} 

function CloseModalTwo() { 
    var modal = document.getElementById('myModalTWO'); 
    modal.style.display = "none"; 
} 

</script>script> 

<center><button id="myBtnTWO"><span class="txt" style="cursor:pointer" onclick="OpenModalTwo();">Link 2</span></button></center> 

<!-- The Modal --> 
<div id="myModalTWO" class="modal"> 

    <!-- Modal content --> 
    <div class="modal-content"> 
    <span class="close" onclick="CloseModalTwo();">&times;</span> 
    <p><ppopup> 
     This is a SECOND TEST 
    </ppopup></p> 
    </div> 
</div> 
関連する問題