这是IE Bug谁有解决办法?_html/css_WEB-ITnose

php中文网
发布: 2016-06-24 11:43:23
原创
1052人浏览过

下边的代码: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>
登录后复制

轻舟办公
轻舟办公

基于AI的智能办公平台

轻舟办公 194
查看详情 轻舟办公

回复讨论(解决方案)

直接用box-button绑定相关事件不就可以了嘛。。。

直接用box-button绑定相关事件不就可以了嘛。。。



不行,其实这只是个例子,真正的情况不是这样的。真正的情况是我的box-cover里面其实是放了flash的。click事件是由flash响应的。

那就用透明呗:

      .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本身不是透明的

那就直接用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>
登录后复制

给 “cover” 一个背景色,让他完全遮住按钮;然后使其完全透明,把按钮的样式露出来。
这样就能解决你的问题。

HTML速学教程(入门课程)
HTML速学教程(入门课程)

HTML怎么学习?HTML怎么入门?HTML在哪学?HTML怎么学才快?不用担心,这里为大家提供了HTML速学教程(入门课程),有需要的小伙伴保存下载就能学习啦!

下载
来源:php中文网
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
最新问题
开源免费商场系统广告
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 举报中心 意见反馈 讲师合作 广告合作 最新更新 English
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号