我有以下代码用于在屏幕的一角显示一个对话框,一旦我点击网页中的链接,它就会显示出来。我想只使用HTML和Javascript(现在没有时间或带宽来学习jQuery)。无论我尝试什么,我点击链接后都没有显示。有什么想法吗?谢谢!
这是我的html文件,包含所有必要的元素:
<!DOCTYPE html>
<head>
<title>Restraint Dialog</title>
<style>
.modalDialog {
position: absolute;
font-family: arial;
font-size:80%;
top: 0;
right: 0;
background: rgba(0,0,0,0.2);
z-index: 99999;
opacity:0;
-webkit-transition: opacity 400ms ease-in;
-moz-transition: opacity 400ms ease-in;
transition: opacity 400ms ease-in;
pointer-events: none;
}
.modalHeader h2 { color: #189CDA; border-bottom: 2px groove #efefef; }
.modalDialog:target {
opacity:1;
pointer-events: auto;
}
.modalDialog > div {
width: 300px;
position: relative;
-webkit-border-radius: 5px;
-moz-border-radius: 5px;
border-radius: 5px;
background: #fff;
}
.modalDialog .modalHeader { padding: 5px 20px 0px 20px; }
.modalDialog .modalContent { padding: 0px 20px 5px 20px; }
.modalDialog .modalFooter { padding: 8px 20px 8px 20px; }
.modalFooter {
background: #F1F1F1;
border-top: 1px solid #999;
-moz-box-shadow: inset 0px 13px 12px -14px #888;
-webkit-box-shadow: inset 0px 13px 12px -14px #888;
box-shadow: inset 0px 13px 12px -14px #888;
}
.modalFooter p {
color:#D4482D;
text-align:right;
margin:0;
padding: 5px;
}
.ok, .close, .cancel {
background: #606061;
color: #FFFFFF;
line-height: 25px;
text-align: center;
text-decoration: none;
font-weight: bold;
-webkit-border-radius: 2px;
-moz-border-radius: 2px;
border-radius: 2px;
-moz-box-shadow: 1px 1px 3px #000;
-webkit-box-shadow: 1px 1px 3px #000;
box-shadow: 1px 1px 3px #000;
}
.close {
position: absolute;
right: 5px;
top: 5px;
width: 22px;
height: 22px;
font-size: 10px;
}
.ok, .cancel {
width:80px;
margin-left:20px;
}
.ok:hover { background: #189CDA; }
.close:hover, .cancel:hover { background: #D4482D; }
.clear { float:none; clear: both; }
</style>
</head>
<body>
<a href="javascript:restraintEditor();">Click to open restraints window</a>
<div id="restraintContainer" class="modalDialog">
<div>
<div class="modalHeader">
<h2>Restraint Editor</h2>
<!--<a href="#close" title="Close" class="close">X</a>-->
</div>
<div class="modalContent">
<div id="restraintLabel"> Name </div>
<div id="restraintText">
<input type="text" id="restraintName" name="restraintName" value="" style="width:200px;"/>
</div>
<div id="restraintDir">
<div id="restraintDirX">
<input type="checkbox" id="restraintX" name="restraintX" value="XDir" checked="checked"/>
<label for="restraintX"> Restrain in X-direction </label>
</div>
<div id="restraintDirY">
<input type="checkbox" id="restraintY" name="restraintY" value="YDir" checked="checked"/>
<label for="restraintY"> Restrain in Y-direction </label>
</div>
<div id="restraintDirZ">
<input type="checkbox" id="restraintZ" name="restraintZ" value="ZDir" checked="checked"/>
<label for="restraintZ"> Restrain in Z-direction </label>
</div>
</div>
</div>
<div class="modalFooter">
<a href="#ok" title="Ok" class="ok">Ok</a>
<a href="#cancel" title="Cancel" class="cancel">Cancel</a>
<div class="clear"></div>
</div>
</div>
<script>
function restraintEditor() {
var restrCont = document.getElementById("restraintContainer");
restrCont.style.display="block";
restrCont.style.visibility="visible";
}
</script>
</body>
</html>
答案 0 :(得分:0)
在脚本中更改以下内容
function restraintEditor() {
var restrCont = document.getElementById("restraintContainer");
restrCont.style.opacity="1";
}
或者
function restraintEditor() {
document.getElementById("restraintContainer").style.opacity="1";
}
答案 1 :(得分:0)
我无法得到你所遇到的确切问题。试着花一些时间用小提琴。看来你是stackoverflow的新手。下次你遇到任何问题时,一定要弄清楚你的代码! !!这肯定会给你准确和更多的解决方案。