模式弹出窗口关闭后仍保留

问题描述 投票:0回答:1

我一直在模态弹出窗口中工作,在该窗口中显示图像并在图像上做标签。模态效果很好,并且图像显示完美,但是我面临的问题是,当我借助按钮关闭模态时,即使关闭模态后,模态背景也会逐渐消失在主窗口中。

我已附上以下代码:

HTML :(模态)

<div id="myModal" class="modal">

<!-- The Close Button -->
<span class="close">&times;</span>

<!-- Modal Content (The Image) -->
<div id="imagearea" class="imagearea">
<img class="modal-content" id="img01">
</div>
<div class="text_container">

  <br>
  <div class="input_tag">
    <span class="right_sec_text">Select a region from the picture</span>
    <div class="tags">

                    </div>
    <div class="input_box">
                                <input type="text" name="tags" class="input_textbox">
                  <button id="settag" class="btn_settag">Set Tag</button>
    </div>
    <div class="footer_btn">
      <p><button class="btn_success">Confirm Selection</button>
      <p><button class="btn_cancel" >Cancel</button>

    </div>
  </div>
</div>
</div>

Javascript :(用于模式和图像上方的框)

var modal = document.getElementById("myModal");

// Get the image and insert it inside the modal - use its "alt" text as a caption
var img = document.getElementById("imgside");
var modalImg = document.getElementById("img01");
img.onload = function(){
modal.style.display = "block";
modalImg.src = this.src;
}

// Get the <span> element that closes the modal
var span = document.getElementsByClassName("close")[0];

// When the user clicks on <span> (x), close the modal
span.onclick = function() {
modal.style.display = "none";
}

function preview(img, selection) {
        if (!selection.width || !selection.height)
            return;
        $('#x1').val(selection.x1);
        $('#y1').val(selection.y1);
        $('#x2').val(selection.x2);
        $('#y2').val(selection.y2);
        $('#w').val(selection.width);
        $('#h').val(selection.height);
        $('.img_error').removeClass("error");
    }

  $(function() {
  $('#img01').imgAreaSelect({
  handles: true,
  fadeSpeed: 200,
  onSelectChange: preview
 });
 });

$(".btn_cancel").click(function(){
$('#myModal').hide();
$('.imagearea').removeClass().removeAttr('style');
$('.modal-backdrop').remove();
});

Picture1 :(带有图像的模态)

enter image description here

图片2 :(关闭后为模态)

enter image description here

当单击btn_cancel按钮时,我尝试从模式中删除样式和div,但没有用。有人可以帮我解决这个问题。

javascript html jquery css bootstrap-modal
1个回答
0
投票

无法在没有img01但使用引导程序模式的情况下尝试在JSFiddle中复制,您应该使用$('#myModal').modal('hide')隐藏>

参考来源:https://getbootstrap.com/2.3.2/javascript.html#modals

© www.soinside.com 2019 - 2024. All rights reserved.