单击按钮时将显示Div弹出窗口 [英] Div popup will come when button click

查看:79
本文介绍了单击按钮时将显示Div弹出窗口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨朋友们,你们可以给我任何建议,当我们点击按钮时,一个div将作为弹出窗口出现在那个地方,只有单行示例如下所示



-----------------

| div弹出|

-----------------

|

|

|

按钮



当我点击按钮时,我的div会弹出那个地方的单行

任何想法请给我



我尝试过:



我尝试下面的代码,它会弹出关闭按钮,不需要关闭按钮,弹出窗口就会出现在页面中心。



<!DOCTYPE html> 
< html>
< head>
< style>
/ *模态(背景)* /
.modal {
display:none; / *默认隐藏* /
位置:固定; / *留在原地* /
z-index:1; / *坐在上面* /
填充顶部:100px; / *方块的位置* /
左:0;
top:0;
宽度:100%; / *全宽* /
高度:100%; / *全高* /
溢出:自动; / *如果需要,启用滚动* /
background-color:rgb(0,0,0); / *后备颜色* /
background-color:rgba(0,0,0,0.4); / *黑色带不透明度* /
}

/ *模态内容* /
.modal-content {
background-color:#fefefe;
保证金:auto;
填充:20px;
border:1px solid#888;
宽度:80%;
}

/ *关闭按钮* /
.close {
颜色:#aaaaaa;
float:right;
字体大小:28px;
font-weight:bold;
}

.close:hover,
.close:focus {
color:#000;
text-decoration:none;
cursor:pointer;
}
< / style>
< / head>
< body>

< h2>模态示例< / h2>

<! - 触发/打开模态 - >
< button id =myBtn> Open Modal< / button>

<! - 模态 - >
< div id =myModalclass =modal>

<! - 模态内容 - >
< div class =modal-content>
< span class =close>×< / span>
< p>模态中的一些文字..< / p>
< / div>

< / div>

< script>
//获取模态
var modal = document.getElementById('myModal');

//获取打开模态的按钮
var btn = document.getElementById(myBtn);

//获取< span>关闭模态的元素
var span = document.getElementsByClassName(close)[0];

//当用户点击按钮时,打开模态
btn.onclick = function(){
modal.style.display =block;
}

//当用户点击< span>时(x),关闭模态
span.onclick = function(){
modal.style.display =none;
}

//当用户点击模态之外的任何地方时,关闭它
window.onclick = function(event){
if(event.target = = modal){
modal.style.display =none;
}
}
< / script>

< / body>
< / html>

解决方案

使用 Bootstrap Modal



它可以减轻你的后顾之忧...... ^ _ ^


< blockquote>在页面中连接bootstrap.css - 在某些情况下,简单的Jquery-ui对话框对于初学者来说很难。



< div class =提醒成功>您的内容< / div> 


Hi friends can you give me any suggestion for when we click on button, one div will come as popup in that place only with single line example as give below

-----------------
| div pop up |
-----------------
|
|
|
Button

When i click the button my div will come as popup in that place with single line
any idea please give me

What I have tried:

I tried below code it will showing pop up with close button no need for close button and pop up is coming in center of page.

<!DOCTYPE html>
<html>
<head>
<style>
/* The Modal (background) */
.modal {
    display: none; /* Hidden by default */
    position: fixed; /* Stay in place */
    z-index: 1; /* Sit on top */
    padding-top: 100px; /* Location of the box */
    left: 0;
    top: 0;
    width: 100%; /* Full width */
    height: 100%; /* Full height */
    overflow: auto; /* Enable scroll if needed */
    background-color: rgb(0,0,0); /* Fallback color */
    background-color: rgba(0,0,0,0.4); /* Black w/ opacity */
}

/* Modal Content */
.modal-content {
    background-color: #fefefe;
    margin: auto;
    padding: 20px;
    border: 1px solid #888;
    width: 80%;
}

/* The Close Button */
.close {
    color: #aaaaaa;
    float: right;
    font-size: 28px;
    font-weight: bold;
}

.close:hover,
.close:focus {
    color: #000;
    text-decoration: none;
    cursor: pointer;
}
</style>
</head>
<body>

<h2>Modal Example</h2>

<!-- Trigger/Open The Modal -->
<button id="myBtn">Open Modal</button>

<!-- The Modal -->
<div id="myModal" class="modal">

  <!-- Modal content -->
  <div class="modal-content">
    <span class="close">×</span>
    <p>Some text in the Modal..</p>
  </div>

</div>

<script>
// Get the modal
var modal = document.getElementById('myModal');

// Get the button that opens the modal
var btn = document.getElementById("myBtn");

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

// When the user clicks the button, open the modal 
btn.onclick = function() {
    modal.style.display = "block";
}

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

// When the user clicks anywhere outside of the modal, close it
window.onclick = function(event) {
    if (event.target == modal) {
        modal.style.display = "none";
    }
}
</script>

</body>
</html>

解决方案

Use Bootstrap Modal.

It could lessen your worries... ^_^


wire up bootstrap.css in page - Simple, Jquery-ui dialog is difficult for beginner in some instance.

<div class="alert success">Your Content</div>


这篇关于单击按钮时将显示Div弹出窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆