简体   繁体   English

离子JavaScript数据删除引导模态不起作用

[英]Ionic javascript data-dismiss bootstrap modal not working

I'm trying to write a function in JavaScript that opens an model when a player enters a certain box. 我正在尝试用JavaScript编写一个函数,当玩家进入某个盒子时打开一个模型。 The model does pop up, but it no longer closes. 该模型会弹出,但不再关闭。

This is used to open the model : 这用于打开模型:

The JavaScript: JavaScript:

superFight(){
function ModalLink(){
  $('#myModal').modal('show');
}

ModalLink();
}

The HTML Model: HTML模型:

<div id="myModal" class="" role="dialog">
  <div class="modal-dialog">
   <div class="modal-content">
    <div class="modal-header">
     <button type="button" class="close" data-dismiss="modal">&times;</button>
     <h4 class="modal-title">Modaldd Header</h4>
    </div>
    <div class="modal-body">
     <p>Some text in the modal.</p>
    </div>
    <div class="modal-footer">
     <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
    </div>
   </div>
  </div>
</div>

I already tried to use $('#myModal').modal('hide'); 我已经尝试使用$('#myModal').modal('hide'); and $('#myModal').modal({ show: false}); $('#myModal').modal({ show: false});

This did not work. 这没有用。 When I put it in the console, it gave : 当我将其放入控制台时,它给出了:

> $('#myModal').modal({ show: false});
< false = $1

I also tried an onClick function in the close button to activate a function to close the modal, but this not work either. 我还尝试了关闭按钮中的onClick函数来激活关闭模式的函数,但这也不起作用。

Basically what I'm trying to do, is to open and close an modal programmatically. 基本上,我想做的是以编程方式打开和关闭模式。 Whenever an superFight(); 每当superFight(); is started, it should pop up with some info. 启动后,它应该会弹出一些信息。 And the user should be able to close it when done. 并且用户应该能够在完成后将其关闭。

I'm writing the code in an ionic app. 我在离子应用程序中编写代码。

Figured it out. 弄清楚了。

I changed the code in superFight() to: 我将superFight()的代码更改为:

function superFight(){
  $('#myModal').show();
  $('#myModal').modal('show');
  $( ".simplemodal-overlay" ).show();
}

Added an onClick the HTML: 添加了onClick HTML:

<button type="button" class="close" data-dismiss="modal" onclick="CloseModalSpel()">&times;</button>

And then in the page, I added this function at the bottom: 然后在页面的底部添加此功能:

function CloseModalSpel(){
  $('#myModal').hide();
  $( ".simplemodal-overlay" ).hide();
}

It now opens, and closes the modal. 现在将打开并关闭模式。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM