HTML / CSS / JavaScript - Modal没有弹出/出现在其他东西后面?

时间:2016-06-19 00:18:26

标签: javascript jquery html css

所以我一直在尝试在JSFiddle中创建自己的模态。在我得到了什么之后,我决定把它放在我的网站上,但遗憾的是它出现在其他东西背后。是什么导致的?如果需要,我可以在这里放置索引页面的HTML代码。这是弹出窗口:

https://jsfiddle.net/o6xf5a6d/18/

模态:

HTML:

<h2>System</h2>
<button onclick="sitaSeen('https://steamcommunity-a.akamaihd.net/economy/image/-9a81dlWLwJ2UUGcVs_nsVtzdOEdtWwKGZZLQHTxDZ7I56KU0Zwwo4NUX4oFJZEHLbXH5ApeO4YmlhxYQknCRvCo04DEVlxkKgpovbSsLQJf3qr3czxb49KzgL-KmsjwPKvBmm5D19V5i_rEprP5gVO8v11lZj-gIYbDclRqMA7Zq1S7lOm-0Za6753KmHoxvnQh5y7ZyhWxiRwecKUx0iL1oy6z/60fx60f','M9 Bayonet | Doppler','Battle Scarred',70)">Click</button>
<button id="myBtn">Open Modal</button>
<div id="myModal" class="modal">
  <div class="modal-content">
    <div class="modal-header">
      <span class="close">×</span>
      <h2>Logo</h2>
    </div>
    <div class="modal-body">
      <table class="centered">
        <thead>
          <tr>
            <th data-field="pic"></th>
            <th data-field="id">Item</th>
            <th data-field="name">Conditon</th>
            <th data-field="price">Price</th>
            <th data-field="delete"></th>
          </tr>
        </thead>
          <tbody class="papa">
          </tbody></table>
      <span id="total">Total: $0</span>
      <button class="btn black right">seen</button>
    </div>
  </div>
</div>

JavaScript的:

var modal = document.getElementById('myModal');
var btn = document.getElementById("myBtn");
var span = document.getElementsByClassName("close")[0];
btn.onclick = function() {
  modal.style.display = "block";
}
span.onclick = function() {
  modal.style.display = "none";
}
var total = 0;

function sitaSeen(img, name, condition, price) {
  $('tbody').append("<tr><td><img src=" + img + "></td><td>" + name + "</td><td>" + condition + "</td><td>$" + price + "</td><td><span>X</span></td></tr>");
  total += price;
  $('#total').empty();
  $('#total').append("Total: $" + total);
}
$('.papa').on('click', 'tr span', function(){
        $(this).closest('tr').remove();
});

CSS + Materialisecss

thead, tbody { display: block; }
.papa{
    overflow-y: scroll;
    max-height: 195px;
}
table {
  box-sizing: border-box;
  border-bottom: 3px solid white;
}
td,
th {
  padding-left: 16px;
  min-width: 140px;
  border: 3px solid white;
  font: 14px/40px;
  text-align: left;
}
td {
  color: white;
}
tr {
  display: block;
}
th {
  color: white;
}

table tbody tr:nth-child(even) {
    background-color: #201f1f;
    box-shadow: inset 0px 0px 25px 2px black;
    border-bottom: 1px solid #545254;
}
table tbody tr:nth-child(odd) {
    background-color: #333333;
    box-shadow: inset 0px 0px 25px 2px black;
    border-bottom: 1px solid #545254;
}
#myModal {
  background-color:#545254;
  color:white;
}

1 个答案:

答案 0 :(得分:0)

您可以使用z-index css属性:

#myModal {
  background-color:#545254;
  color:white;
  position: relative;
  z-index: 100;
}

为了使z-index起作用,您需要设置position属性,如图所示。