我希望页面完成加载后立即显示一个弹出窗口。弹出窗口的内容是由div标签的内容给出的html。这是我的代码:

<div style='display:none; width:500px; height:400px; padding:5px; top:0px; left:400px;' id='popup'>
<div style='float:right'><a id='cchiudi'>Chiudi</a></div>
<br style='clear:both' /><br/>
<center>Per i nuovi clienti offriamo 4h di facchnaggio <strong>GRATUITE</strong>
<BR/><br/>
<a href='http://www.ambientaservizi.it/contact'>
<img src='<?php echo $img_popup; ?>'/>
</a>
<br/><br/>
Per ricevere maggiori informazioni o per prenotare il servizio <br/>cliccare <a href='http://www.ambientaservizi.it/contact'>QUI</a> o cliccare sulla immagine.
</center>




<script>
function popUP(){

//jQuery("#popup").show();
var w = 500;
var h = 400;
//scroll = 'yes';
LeftPosition = (screen.width) ? (screen.width-w)/2 : 0;
TopPosition = (screen.height) ? (screen.height-h)/2 : 0;
var windowWidth = document.documentElement.clientWidth;
var windowHeight = document.documentElement.clientHeight;
var popupHeight = jQuery("#popup").height();
var popupWidth = jQuery("#popup").width();
//centering
jQuery("#popup").css({
    "top": "",
    "left": windowWidth/2-popupWidth/2,
});

jQuery("#cchiudi").click(function(){
    jQuery("#popup").hide();
});
window.open(jQuery("#popup").html(), "Avviso", "menubar=no,toolbar=no,status=no, height=500,width=400,top="+TopPosition+",left="+LeftPosition);
}

jQuery(document).ready(function(){
popUP();
});


看起来很简单,但是我什么都不知道,因为什么也没出现。你能帮我吗?

最佳答案

这是你要找的吗
https://jsfiddle.net/2qmc5xoa/

$(document).ready(function(){

  $("button").on('click', function() {
      showPopup();
  });

  $("#maskLayout").on('click', function() {
    hidePopup();
  });

  $("#popup").on('click', function() {
    hidePopup();
  });

  function hidePopup() {

    $("#popup").hide();
    $("#maskLayout").hide();
  }

  function showPopup() {

    $("#popup").show();
    $("#maskLayout").show();
  }
});

关于javascript - Javascript:如何显示具有<div>内容的弹出窗口,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/35864441/

10-11 14:47
查看更多