Home >Web Front-end >JS Tutorial >Detailed description of browser feature detection (1)-jQuery1.4 added part

Detailed description of browser feature detection (1)-jQuery1.4 added part

PHP中文网
PHP中文网Original
2016-05-16 18:16:521198browse

The most classic application is the general addEvent function:

<br>

function addEvent(element, type, handler) { 
if (element.attachEvent) { //IE8及以下浏览器 
element.attachEvent('on' + type, handler); 
} 
else { //W3C标准浏览器 
element.addEventListener(type, handler, false); 
} 
};

The function can determine whether to use attachEvent or addEventListener by detecting whether the attachEvent function exists. This It is also the simplest type of feature detection, so real-time detection is usually performed only when needed. Another kind of feature detection, because the detection process is more troublesome, will complete the detection in advance and save the detection result (usually Boolean type) in a variable.

The main goal of this article is to analyze and explain the new content of browser feature detection in jQuery1.4, and at the same time deepen the memory of several details in browser compatibility.

jQuery 1.4 mainly adds the following browser feature identifiers. This article analyzes them one by one:

  • checkOn

  • Introduced in version 1.4, it determines whether a checkbox with no value set has a default value of "on".

  • optSelected

  • Introduced in version 1.4.3, it determines whether the first option element of the select element will be selected by default Selected.

  • optDisabled

  • Introduced in version 1.4.3, it determines that when the select element is set to disabled, all its option children Whether the element will also be set to disabled.

  • checkClone

  • Introduced in version 1.4.1, it determines whether the radio and checkbox will be used when using the cloneNode function on DocumentFragment The checked attribute is retained.

  • inlineBlockNeedsLayout

  • Introduced in version 1.4.3, it was decided that in IE the next block element has the hasLayout attribute and has display: inline;, whether it will be displayed inline-block.

  • shrinkWrapBlocks

  • Introduced in version 1.4.3, it is decided that the next element in IE will have the hasLayout attribute and a fixed width /height, whether it will not be expanded by child elements.

  • reliableHiddenOffsets

  • Introduced in version 1.4.3, it is determined that when a td or th element is set to display: none;, Is there any offsetHeight?

checkOn

Use the following code to detect this feature:

<br>
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn