Jquery simplemodal call another simplemodal

2019-07-27 14:16发布

问题:

I want to call another simplemodal from a link in existing modal.

I'm using the OSX modal.

How can I do this ?

回答1:

SimpleModal only supports one modal open at a time.

Instead of opening a new one, you could get the content you want and replace the existing content with it.



回答2:

$('#myModal').modal.update();

I think that should instead be $.modal.update(); There's only ever one modal dialog so you don't have to specify which one.



回答3:

There are too many ways to accomplish that. I will show you one of them:

a) Let's say that you are "simpleModal-ing" a div with id "myDisplay":

<div id='myDisplay' style='.........'></div>

b) You, first, loaded the contents for the form in that page (div)

<div id='myDisplay' style='.........'>
 <form ............>
  <input this>
  <input that>
  <submit onClick='updateMyDisplay'>
 </form>
</div>

c) Somewhere between the of your page, put the updating script:

<script type='text/javascript'>  //remember that you could/should have only one of this
   function updateMyDisplay() {
      //plain html/javascript
      document.getElementById('myDisplay').innerHTML="Thank you!";
      .. or ..
      //jquery
      $('#myDisplay').html("Thank you!");
   }
</script> //again : could/should have only one of this

...... The best way to implement such a thing (multiple displays with single modal) is to use the jQuery load():

on the main page or on the page of the script, create an empty hidden div:

<div id='myModal' style='......; overflow:auto; display:none; ' ></div>

then, populate that div with offline (non content in the same page) html pages

the form ....... in the myForm.html file the thanking ... in the thankyou.html file

using jquery (for me the easiest thing out there):

 .......
  $('#myModal').load('myForm.html');
  $('#myModal').height('650px');
  $('#myModal').modal();
 .......
  // on completion of the form:
  $('#myModal').load('thankyou.html');
  $('#myModal').modal.update(); // (Eric Martin, himself, sent me this tip through Twitter)
 .......

Anyways, if you are a "code borrower" ... like I am, you might have troubles undertanding the above but, in any case, I hope I have helped you.