下边的代码:box-button和box-cover都是绝对定位。box-cover是悬浮在box-button之上的,完全遮盖了box-button。box-cover绑定了click事件。box-button里面有文字,如果鼠标点击的区域没有文字,一切正常,但是如果点击在文字上,click事件就无效。当然只是在IE里面,我的是IE 10,大家有没有遇到过这种问题?请问怎么解决?
<!DOCTYPE html><html lang="en" xmlns="http://www.w3.org/1999/xhtml"><head> <meta charset="utf-8" /> <title></title> <style type="text/css"> .box { position:relative; width:500px; margin:30px auto; } .box * { position:absolute; top:0; right:0; width:100px; height:35px; } .box .box-button { background-color:red; color:#FFF; line-height:30px; text-align:center; font-size:14px; } .box .box-cover { z-index:100; cursor:pointer; } </style> <script type="text/javascript"> function docLoad() { document.getElementById("cover").attachEvent("onclick", function () { alert("OK"); }); } </script></head><body onload="docLoad()"> <div class="box"> <div class="box-button">选择</div> <div class="box-cover" id="cover"></div> </div></body></html>
直接用box-button绑定相关事件不就可以了嘛。。。
直接用box-button绑定相关事件不就可以了嘛。。。
那就用透明呗:
.box .box-cover { z-index:100; cursor:pointer;background:yellow;filter:alpha(opacity=0.1); -moz-opacity:0.1; -khtml-opacity: 0.1; opacity: 0.1;}
那就用透明呗:
.box .box-cover { z-index:100; cursor:pointer;background:yellow;filter:alpha(opacity=0.1); -moz-opacity:0.1; -khtml-opacity: 0.1; opacity: 0.1;}
那就用透明呗:
.box .box-cover { z-index:100; cursor:pointer;background:yellow;filter:alpha(opacity=0.1); -moz-opacity:0.1; -khtml-opacity: 0.1; opacity: 0.1;}
那就直接用div上的onclick实现就好了呗。。。
<!DOCTYPE html><html lang="en" xmlns="http://www.w3.org/1999/xhtml"><head> <meta charset="utf-8" /> <title></title> <style type="text/css"> .box { position:relative; width:500px; margin:30px auto; } .box * { position:absolute; top:0; right:0; width:100px; height:35px; } .box .box-button { background-color:red; color:#FFF; line-height:30px; text-align:center; font-size:14px; } .box .box-cover { z-index:100; cursor:pointer; } </style> <script type="text/javascript"> function aa(){ alert("OK"); } </script></head><body onload="docLoad()"> <div class="box"> <div class="box-button">选择</div> <div class="box-cover" id="cover" onclick="aa()"></div> </div></body></html>
<style type="text/css"> #cover { background-color: green; filter:alpha(opacity=0); }</style>