我有一个css popup div,当它通过onClick加载时,它也会带来一层透明度,就像Facebook在你看照片时的表现一样
当我点击毯子时,如何让弹出窗口关闭?
继承代码
<center><div id="blanket" style="display:none;">
</div>
<table width="1000" border="0">
<tr>
<td>
<div id="mainAdminCP">
<div class="editRecipe" >
<a href="#" onclick="popup('popUpAdminEditRecipe');return false;"><h2>Edit Recipe</h2></a>
</div>
<div id="popUpAdminEditRecipe" style="display:none;" align="center">
<br />
<br />
<form id="editRecipe">
<fieldset id="inputs">
<input id="username" type="text" placeholder="Please insert the name of the recipe" autofocus required>
<br />
<br />
<input id="add" type="text" placeholder="Recipe Name" required>
<input id="add" type="text" placeholder="Recipe Ingredients" required>
<input id="add" type="text" placeholder="Recipe Instructions" required>
<input id="add" type="text" placeholder="Recipe Image" required>
</fieldset>
<fieldset id="actions">
<input type="submit" id="submit" value="Save Changes">
<input type="submit" id="submit" onClick="popup('popUpAdminEditRecipe')" value="Close">
</fieldset>
</form>
</div>
<div class="editCoins">
<a href="#" onclick="popup('popUpAdminEditCoins');return false;"><h2>Edit Coins</h2></a>
</div>
<div id="popUpAdminEditCoins" style="display:none;" align="center">
<br />
<br />
<form id="login">
<fieldset id="inputs">
<input id="username" type="text" placeholder="Please insert the Username of the User" autofocus required>
<input id="add" type="text" placeholder="Add Coins" required>
<input id="add" type="text" placeholder="Subtract Coins" required>
</fieldset>
<fieldset id="actions">
<input type="submit" id="submit" value="Submit">
<input type="submit" id="submit" onClick="popup('popUpAdminEditCoins')" value="Close">
</fieldset>
“
接下来是页面本身的链接,以获得我正在寻找的明确例子。
http://teknologenie.com/fruitforest/admincp.php
我试过放置
<a href="#" onClick="popup('popUpAdminEditUser')" > </a>
在毯子里面,没什么。只是把一切搞砸了。
修改 此外,如果你访问链接,然后单击文本,整个div不会直接在屏幕中间,我需要它。任何解决方案?
答案 0 :(得分:2)
不是在毯子div中放置一个链接,而是在毯子div上创建一个onclick函数:
<div id="blanket" onclick="closePopup()" style="height: 681px; display: block;"></div>
函数closePopup然后应该将display none设置为弹出窗口和毯子:
function closePopup() {
document.getElementById('blanket').style.display = 'none';
document.getElementById('popUpAdminEditCoins').style.display = 'none';
}
答案 1 :(得分:1)
我在这里给你写了一个例子:http://jsfiddle.net/KXK6E/2/
在javascript中绑定事件而不是在HTML中,你会好得多。
document.getElementById("blanket").onclick = function(e){
document.getElementById("popup").style.display = "none";
e.target.style.display = "none";
};
document.getElementById("trigger").onclick = function(){
document.getElementById("blanket").style.display = "block";
document.getElementById("popup").style.display = "block";
}