我有这段 html/css,我需要通过单击 js 按钮更改 div 样式,以便我的 div 变得可见和可点击。我似乎做的一切都是对的,但由于某种原因它不起作用。
当我点击那个按钮时,什么也没有发生,有人能帮忙吗?
<button type="button" id="letsgo" onclick="letitGo()">Process</button>
<div id="textualdiv">blah blah blah</div>
下面是一个脚本:
<script>
function letitGo()
{
document.getElementById("textualdiv").style.opacity="1";
document.getElementById("textualdiv").style.pointer-events="auto";
}
</script>
和 div 样式在一个单独的 CSS 文件中:
#textualdiv {
z-index:10;
background-color:white;
margin-bottom:0%;
width:70%;
text-align:center;
height:50%;
min-width:500px;
top: 10%;
display: block;
margin: 0 auto !important;
padding:0;
position:relative;
opacity:0;
pointer-events: none;
border-style:solid;
-webkit-border-radius: 4px;
-moz-border-radius: 4px;
border-radius: 4px;
}
最佳答案
CSS pointer-events
属性在 JavaScript 中是 elem.style.pointerEvents
改用这个
function letitGo()
{
document.getElementById("textualdiv").style.opacity="1";
document.getElementById("textualdiv").style.pointerEvents="auto";
}
JSFiddle - http://jsfiddle.net/dbxcsv9h/
关于javascript - 单击按钮更改 div css 不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32686058/