IIssNan's Notes

Quick notes


  • 首页

  • 归档

  • 标签

  • 搜索

IE 下 iframe 存取 cookie

发表于 2011-09-08 | | 阅读次数

IE6 后引入了 P3P。

解决方法:在回应的 HTTP HEADER 中输出 P3P,比如在 PHP 中:

1
header('P3P: CP=CAO PSA OUR');

insertBefore

发表于 2011-09-07 | | 阅读次数

insertBefore() 方法可在已有的子节点前插入一个新的子节点。此方法可返回新的子节点。

1
insertBefore(newchild, refchild);

在 IE 中如果没有 refchild,那么 insertBefore() 方法第二个参数不要指定。而在 Firefox/Google Chrome 等需要设定为 null。

考虑往列表 ul中插入列表项 li:

1
2
3
4
5
6
7
8
var firstItem = ul.childNodes[0];
// 判断ul是否存在子元素
if (!firstItem) {
document.all ? oUl.insertBefore(li) : ul.insertBefore(li, null);
} else {
ul.insertBefore(li, firstItem);
}

参考资料:

  • insertBefore Method - MSDN

Using jQuery to test if an input is focus

发表于 2011-09-01 | | 阅读次数

Using jQuery to test if an input has focus - StackOverflow

jQuery 1.6+

jQuery added a :focus selector so we no longer need to add it ourselves…

1
return $('elem').is(':focus') ? true : false;

jQuery 1.5 and below

1
2
3
jQuery.expr[':'].focus = function( elem ) {
return elem === document.activeElement && (elem.type || elem.href);
};

Any version of jQuery

If you just want to figure out which element has focus, you can use $(document.activeElement); If you aren’t sure if the version will be 1.6 or lower, you can add the :focus selector if it is missing:

1
2
3
4
5
6
7
8
9
(function ($) {
var filters = $.expr[":"];
if (!filters.focus) {
filters.focus = function( elem ) {
return elem === document.activeElement && (elem.type || elem.href);
};
}
})(jQuery);

使用 JavaScript 更改具有 !important 声明的样式规则

发表于 2011-08-30 | | 阅读次数

如果在 CSS 中使用 !important 属性声明规则,那么在 JavaScript 中需要使用 cssText 属性对样式进行修改。

  • 如果元素仅有一条规则,可以直接将新规则(带 !important 声明)复制给 cssText:

    1
    element.style.cssText = 'display:inline !important';
  • 如果元素具备多条规则,则需要将新规则加到 cssText 中:

    1
    element.style.cssText += 'display:inline !important';

参考资料:

  • Overriding !important style using Javascript

特性判断 IE 浏览器

发表于 2011-08-28 | | 阅读次数

一、使用 document.all

1
2
3
function isIE(){
return document.all ? true : false;
}

二、判断 window.ActiveXObject

1
2
3
function isIE(){
return !!window.ActiveXObject ? true : false;
}

三、判断 currentStyle,得排除 Opera 浏览器

1
2
3
function isIE(){
return (document.body.currentStyle && !window.opera) ? true : false;
}
1…353637
IIssNan

IIssNan

胡编一通,乱写一气

183 日志
6 分类
111 标签
RSS
GitHub Twitter 豆瓣 知乎
© 2011 - 2017 IIssNan
由 Hexo 强力驱动
主题 - NexT.Pisces
0%