简体   繁体   English

使用JavaScript显示多个CSS弹出窗口

[英]Display multiple CSS popups using JavaScript

I not familiar with JavaScript. 我不熟悉JavaScript。 In my project I want to make a CSS popup. 在我的项目中,我想制作一个CSS弹出窗口。 I created a pop up using CSS and JavaScript. 我使用CSS和JavaScript创建了一个弹出窗口。

JavaScript: JavaScript:

 function ShowPop(id)
 { 

  document.getElementById(id).style.visibility = "visible";
  }

CSS: CSS:

 .popup
  {

    position: absolute; 
    left:400px; 
    top:100px; width:230px;
    border-style:solid;
    padding: 5px;
    z-index:2;
    visibility:hidden;
 }

HTML: HTML:

  <a href='javascript:void(0);' onclick='ShowPop("term1")>a</a>
  <span id='term1'></span>

My doubt is how to open multiple pop ups at time, with using only one <span id='term1'></span> . 我的疑问是如何仅使用一个<span id='term1'></span>一次打开多个弹出窗口。 Each pop up has to contain different content retrieved from a database. 每个弹出窗口必须包含从数据库检索到的不同内容。 How to open multiple CSS popups? 如何打开多个CSS弹出窗口?

Hope this helps you, it's how I've done it: 希望这对您有所帮助,这就是我的做法:

http://jsfiddle.net/F5VCJ/ http://jsfiddle.net/F5VCJ/

EDIT: I haven't implemented any functionality to move the dialog around though, so at the moment you're the one who'll have to implement that, but for now you could simply give different classes to the dialogs to position them, or write some code to make them appear next to a given element. 编辑:我还没有实现任何功能来移动对话框,所以现在您是必须实现该功能的人,但是现在您可以简单地给对话框提供不同的类来放置它们,或者编写一些代码,使它们出现在给定元素的旁边。

If you want multiple popups opened at any one time, you'll need multiple elements to display the data in. The easiest way to do that would be to use one of the many jQuery plugins that have already been written to do this - having never used one myself, I can't provide any suggestions, but a quick Google search should be sufficient. 如果您想一次打开多个弹出窗口,则需要多个元素来显示数据。最简单的方法是使用已经编写的许多jQuery插件之一-从不我自己一个人使用,我无法提供任何建议,但是快速的Google搜索就足够了。

If, however, you really wanted to implement this yourself, you'd need to create the elements on demand using jQuery, load the relevant data (determined by which link was clicked on) into the newly created element, then add it to the DOM and make it visible. 但是,如果您确实想自己实现,则需要使用jQuery按需创建元素,将相关数据(由单击哪个链接确定)加载到新创建的元素中,然后将其添加到DOM中。并使其可见。 Then, when the user chooses to close the popup, simply remove that element again. 然后,当用户选择关闭弹出窗口时,只需再次删除该元素。

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

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