浏览器不支持removeAttribute()的解决方法

今天在做一个网页的时候,想实现 mouse over 时候给 li 加载 background-image,在 mouse out 时候移除 background-image。 通过 js 实现: if(action == 0) { btn.style.backgroundImage = "url(images/index_nav1_07.jpg)"; btn.style.backgroundRepeat = "repeat-x"; } else { btn.removeAttribute("style"); } 发现可以兼容 ff 和 ie,但是在 chrome 下 mouse out 动作没有执行。 后发现可能是 chrome 不支持 removeAttribute(),于是加入兼容写法: if(action == 0) { btn.style.backgroundImage = "url(images/index_nav1_07.jpg)"; btn.style.backgroundRepeat = "repeat-x"; } else { btn.style.backgroundImage = ""; btn.style.backgroundRepeat = ""; btn.removeAttribute("style"); } 此方法实现了 ff、ie 和 chrome 兼容。 ...

十月 20, 2012 · 1 分钟 · Zhiya

解决超链接点击后周围有虚线框的问题

在火狐或 IE 浏览器中点击点击<a>标签,标签周围会出现虚线框(如图),影响美观。 针对 IE 浏览器解决这个问题的方法是将 hidefocus="hidefocus" 添加到<a>标签中。 针对 firefox 浏览器的方法是添加 css 属性 outline:none

十月 20, 2012 · 1 分钟 · Zhiya