我们可以在一页中有两个弹出窗口吗
Can we have two popup windows in single page?
function myFunction() {
document.getElementById("myDIV1").style.display = "none";
document.getElementById("myDIV").style.display = "inline";
}
function myFunction1() {
document.getElementById("myDIV1").style.display = "inline";
document.getElementById("myDIV").style.display = "none";
}
#myDIV {
position: fixed;
top: 40px;
left: 7px;
width: 1212px;
height: 620px;
display: none;
z-index: 600;
}
#myDIV1 {
position: fixed;
top: 40px;
left: 7px;
width: 1212px;
height: 620px;
display: none;
z-index: 600;
}
#shadow {
background: rgba(202, 188, 160, 0.6);
position: fixed;
top: 47px;
left: 213px;
width: 801px;
height: 570px;
-webkit-box-shadow: 9px 5px 27px 5px rgba(71, 68, 71, 0.57);
-moz-box-shadow: 9px 5px 27px 5px rgba(71, 68, 71, 0.57);
box-shadow: 9px 5px 27px 5px rgba(71, 68, 71, 0.57);
}
.privacy-stat {
background: rgba(254, 254, 254, 0.9);
position: fixed;
width: 759px;
height: 500px;
overflow: auto;
top: 75px;
margin: auto;
padding: 20px;
left: 213px;
border-width: 1px;
border-style: solid;
border-bottom-color: #666666;
border-left-color: #666666;
border-top-color: #666666;
border-right-color: #666666;
}
#title-bar {
background-color: #CCCCCC;
width: 799px;
height: 27px;
position: fixed;
left: 213px;
top: 47px;
border-width: 1px;
border-style: solid;
border-bottom: none;
border-left-color: #666666;
border-top-color: #666666;
border-right-color: #666666;
z-index: 600;
}
#close {
position: fixed;
width: 26px;
height: 26px;
position: relative;
left: 769px;
top: -1px;
}
<a onClick="myFunction()" href="#" class="button"><span>ADD EMPLOYEE</span></a>
<a onclick="myFunction1()" href="#" class="button"><span>EDIT</span></a>
<div id="myDIV">
<div id="shadow">
<div class="privacy-stat">
<div id="title-bar">
<div id="close">
<a href="employee/list"><img src="<?php echo base_url(); ?>assets/img/cancel.svg" height="30" width="30"/></a>
</div>
</div>
<div class="sky-tabs sky-tabs-pos-top-left sky-tabs-response-to-icons">
<input type="radio" name="sky-tabs" checked="" id="sky-tab1" class="sky-tab-content-1">
<label for="sky-tab1"><span><span>Contact</span></span>
</label>
<input type="radio" name="sky-tabs" id="sky-tab2" class="sky-tab-content-2">
<ul>
<li class="sky-tab-content-1">
<div class="typography">
style="word-spacing: 1px;font-size:12px;">
<fieldset>
<legend>
<p>GENERAL</p>
</legend>
<div class="inputwrap">
<label>Employee id:</label>
<input type="text" id="" name="id" value="<?php echo set_value('id'); ?>">
</div>
</br>
<div class="inputwrap">
<label>First name:</label>
<input type="text" id="" name="emp_first_name" pattern="[a-zA-Z]+" title="enter a valid name only characters are allowed" value="<?php echo set_value('emp_first_name'); ?>">
</div>
</br>
<div class="inputwrap">
<label for="inputError">Last name:</label>
<input type="text" id="" name="emp_last_name" pattern="[a-zA-Z]+" title="enter a valid name only characters are allowed" value="<?php echo set_value('emp_last_name'); ?>">
</div>
</br>
<div class="inputwrap">
<label for="inputError" class="control-label">Email id</label>
<input type="text" id="" name="emp_email_id" pattern="^'w+@[a-zA-Z_]+?'.[a-zA-Z]{2,3}$" title="enter a valid email for example sample@sample.com" value="<?php echo set_value('emp_email_id'); ?>">
</div>
</br>
<div class="inputwrap">
<label for="inputError">Emergency contact</label>
<input type="text" name="emp_emergency_contact" pattern="[0-9]{10}" title="enter valid contact. it must contain 10 digits" value="<?php echo set_value('emp_emergency_contact'); ?>">
</div>
</br>
<div class="inputwrap">
<label>Category:</label>
<?php echo form_dropdown( 'category', $options_designation, set_value( 'category'), 'class="span2"'); ?>
</div>
</br>
<div id="designation">
<?php if($this->uri->segment(2) == 'designation');?>
<a href="<?php echo base_url();?>admin/designation" class="button"><span>Add</span></a>
</div>
</br>
<div class="inputwrap">
<label>Date of hire</label>
<input type="date" name="emp_date_of_hire" value="<?php echo set_value('emp_date_of_hire'); ?>">
</div>
</br>
<div class="inputwrap">
<label>Date of termination</label>
<input type="date" name="emp_date_of_termination" value="<?php echo set_value('emp_date_of_termination'); ?>">
</div>
</br>
<div class="inputwrap">
<label>Date of rehire</label>
<input type="date" name="emp_date_of_rehire" value="<?php echo set_value('emp_date_of_rehire'); ?>">
</div>
</br>
<div class="inputwrap">
<label>Referenece number</label>
<input type="text" name="emp_reference_num" pattern="[0-9]{10}" title="enter valid contact. it must contain 10 digits" value="<?php echo set_value('emp_reference_num'); ?>">
</div>
</br>
<div class="inputwrap">
<label>System name</label>
<input type="text" name="system_name" value="<?=$system_name ?>">
</div>
</br>
<div class="inputwrap">
<button id="btn" type="submit">NOTES</button>
<button id="btn" type="submit">SAVE</button>
<button id="btn" type="reset">CANCEL</button>
</div>
</fieldset>
<?php echo form_close(); ?>
</fieldset>
</FONT>
</div>
</li>
</ul>
</div>
</div>
</div>
<!--For edit-->
<div id="myDIV1">
<div id="shadow">
<div class="privacy-stat">
<div id="title-bar">
<div id="close">
<a href="employee/list"><img src="<?php echo base_url(); ?>assets/img/cancel.svg" height="30" width="30"/></a>
</div>
</div>
<div class="sky-tabs sky-tabs-pos-top-left sky-tabs-response-to-icons">
<input type="radio" name="sky-tabs" checked="" id="sky-tab1" class="sky-tab-content-1">
<label for="sky-tab1"><span><span>Contact</span></span>
</label>
<ul>
<li class="sky-tab-content-1">
<div class="typography">
<p>This my edit page<p>
</ul>
</div>
</div>
</div>
<!--Edit end-->
我正在使用codeigniter。在我的视图页面中,我有两个元素添加和编辑。对于弹出式窗口,我使用了元素。对于单按钮操作,我可以得到结果,但当我有两个按钮时,它不起作用。有人能解决这个问题吗?请帮我编码。我有这个剧本。在这里,我更改div元素的显示属性。此div元素仅在单击按钮时显示。
<script>
function myFunction() {
document.getElementById("myDIV").style.display = "inline";
}
function myFunction1() {
document.getElementById("myDIV1").style.display = "inline";
}
</script>
这是我的CSS。在这里,我有每个弹出窗口的myDiv
和myDiv1
。
#myDIV {
position: fixed;
top: 40px;
left: 7px;
width: 1212px;
height: 620px;
display: none;
z-index: 600;
}
#myDIV1 {
position: fixed;
top: 40px;
left: 7px;
width: 1212px;
height: 620px;
display: none;
z-index: 600;
}
我的视图页面。这里我有两个按钮操作添加和编辑。在这里我调用了我的脚本。
<div id="add">
<a onClick="myFunction()" href="#" class="button"><span>ADD EMPLOYEE</span></a>
<a onclick="myFunction1()" href="#" class="button"><span>EDIT</span></a>
</div>
这是我的弹出窗口内容。
<div id="myDIV">
....
</div>
<div id="myDIV1">
.....
</div>
当添加另一个按钮操作时,它也会干扰第一个弹出窗口的结果。
我认为您的问题是,当您再次单击ADD EMPLOYEE
按钮时,它不会隐藏EDIT
弹出窗口,也不会显示myDIV
弹出窗口。
要解决这个问题,您需要做的是,每次单击其中一个按钮时,首先使用style.display = 'none'
隐藏现有弹出窗口。然后显示相关的弹出窗口。
function myFunction() {
document.getElementById("myDIV1").style.display = "none";
document.getElementById("myDIV").style.display = "inline";
}
function myFunction1() {
document.getElementById("myDIV").style.display = "none";
document.getElementById("myDIV1").style.display = "inline";
}
#myDIV {
position: fixed;
top: 40px;
left: 7px;
width: 1212px;
height: 620px;
display: none;
z-index: 600;
}
#myDIV1 {
position: fixed;
top: 40px;
left: 7px;
width: 1212px;
height: 620px;
display: none;
z-index: 600;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css" rel="stylesheet"/>
<div id="myDIV">
MY DIV
</div>
<div id="myDIV1">
MY DIV 1
</div>
<div id="add">
<a onClick="myFunction()" href="#" class="button"><span>ADD EMPLOYEE</span></a>
<a onclick="myFunction1()" href="#" class="button"><span>EDIT</span></a>
</div>
您需要将<a herf="javascript:void(0);"></a>
添加到锚定标记中,然后它就可以工作了。查找codepen演示
<div id="add">
<a href="javacsript:void(0);" onclick="myFunction()" class="button"><span>ADD EMPLOYEE</span></a>
<a href="javascript:void(0);" onclick="myFunction1()" class="button"><span>EDIT</span></a>
</div>
<div id="myDIV">myDIV</div>
<div id="myDIV1">myDIV1</div>
相关文章:
- 在两个窗口中都打开页面
- 一个链接打开两个窗口
- Bootbox,两个模式窗口-一个在另一个之上
- jquery-mobile的列表视图中的两个弹出窗口
- btAdd click事件在添加记录后打开两个窗口
- JavaScript:window.conf,有两个窗口位置
- 两个窗口之间的 Websocket 通信
- 一键在一个窗口中打开两个不同的链接图像
- 发布消息 两个具有相同来源的子窗口
- 打开窗口-一键打开两个窗口
- Javascript 多线程两个窗口焦点
- 如何在Protractor中比较两个窗口之间两个元素的值
- 两个窗口.在网站上打开
- 两个窗口或选项卡之间的跨文档消息传递,而不是iframe
- 套接字.io:如何处理打开两个窗口的认证客户端
- 两个窗口的Javascript代码可用性.加载和文档.准备好了
- 可以在两个窗口之间进行交互
- 在两个窗口之间交换信息
- 单击打印Codeigniter,Javascript时打开两个窗口
- Javascript两个窗口.点击功能冲突