随笔分类 -  js那些事

上一页 1 2

setattribute兼容
摘要:var spanElement = document.getElementById("mySpan"); spanElement.style.cssText = "font-weight:bold;color:red;"; 这种方法在IE和大多数其他浏览器上都能很好地工作,只有Opera除外, 为了让代码能在所有当前浏览器上都可以移值,可以同时使用这两种方法,如下所示: var spanElement = document.getElementById("mySpan"); spanElement.setAttribute(" 阅读全文

posted @ 2013-09-11 11:57 rainbow661314 阅读(103) 评论(0) 推荐(0)

IE6/7中setAttribute不支持class/for/rowspan/colspan等属性
摘要:如设置class属性?1el.setAttribute('class', 'abc');在IE6/7中样式“abc”将没有起作用,虽然使用el.getAttribute('class')能取到值“abc”。又如for属性?12345姓名:我们知道当lab设置了for属性,点击label将自动将对应的checkbox选中。但以上设置在IE6/7点击将不会选中checkbox。类似的情况还发生在cellspacing/cellpadding 上。汇总如下:classforcellspacingcellpaddingtabindexreadonlyma 阅读全文

posted @ 2013-08-30 17:43 rainbow661314 阅读(259) 评论(0) 推荐(0)

json格式的转换为json字符串函数
摘要:function toJSON(object){ var type = typeof object; if ('object' == type) { if (Array == object.constructor) type = 'array'; else if (RegExp == object.constructor) type = 'regexp'; ... 阅读全文

posted @ 2013-07-31 09:48 rainbow661314 阅读(424) 评论(0) 推荐(0)

correctly handle PNG transparency in Win IE 5.5 & 6.
摘要:function correctPNG() // correctly handle PNG transparency in Win IE 5.5 & 6. { var arVersion = navigator.appVersion.split("MSIE") var version = parseFloat(arVersion[1]) if ((version >= 5.5) && (document.body.filters)) { for(var j=0; j" img.outerHTML = strNewHTML ... 阅读全文

posted @ 2013-07-29 11:02 rainbow661314 阅读(160) 评论(0) 推荐(0)

阻止默认行为stopDefault
摘要:function stopDefault(e){ if(e && e.preventDefault) e.preventDefault(); else window.event.returnValue = false; //ff? return false;}; 阅读全文

posted @ 2013-07-24 16:06 rainbow661314 阅读(666) 评论(0) 推荐(0)

document.execCommand(”BackgroundImageCache”, false, true)
摘要:很多时候我们要给一些按钮或是img设置背景,而为了达到数据与表现样式分离的效果,通常背景样式都是在CSS里设定的,但是这个行为在IE会有一 个Bug,那就是因为 IE默认情况下不缓存背景图片,所以当鼠标在有CSS背景的按钮或是图片上移动时,图片会闪烁甚至鼠标会出现忙的状态,而在FireFox下没有这个问 题,为了解决这个问题,有两种解决办法,其一是在CSS中加入如下样式:html {filter: expression(document.execCommand(”BackgroundImageCache”, false, true));}但这个可能会使整个页面的加载变得很慢,所以推荐使用JS来 阅读全文

posted @ 2013-07-22 10:11 rainbow661314 阅读(2368) 评论(1) 推荐(0)

上一页 1 2