var div = document.createElement ("div" ); div.setAttribute("className", "t"); div.innerHTML = "
TABLE>a "; all = div.getElementsByTagName("*"); a = div.getElementsByTagName("a")[0]; var select = document.createElement("select"); opt = select .appendChild(document.createElement("option")); input = div.getElementsByTagName("input")[0]; The div element is quite connotative. Including blank beginning, empty Table element, inline style, opacity, etc. There are no other notes besides reading the code and comments line by line:
support = { // IE will remove the leading spaces, so nodeType is not 3 (text) leadingWhitespace: (div.firstChild.nodeType === 3), // IE will automatically Insert tbody, so the length is different tbody: !div.getElementsByName("tbody").length, // IE does not allow link elements to be inserted in this way htmlSerialize: !!div.getElementsByTagName(" link").length, // If the style is obtained normally, this regular expression should pass normally style: /top/.test(a.getAttribute("style")), / / The href attribute should be the original specified string, and IE will modify it to the absolute URL starting with http hrefNormalized: (a.getAttribute("href") === "/a"), // can be obtained opacity attribute. Regular expressions are used here to bypass WebKit [bug No. 5145](http://dev.jquery.com/ticket/5145) // But this should be a problem in an early version. At least in Chrome 13, it is correct not to use regular expressions. opacity: /^0.55$/.test(a.style.opacity), // IE uses styleFloat cssFloat: !!a.style.cssFloat, // checkbox in div If no value is specified, see if the default value is on. WebKit is "". So my result is false checkOn: (input.value === "on"), // This select only has one option element, so when rendering, this option is selected by default. Selected should be true at this time. optSelected: opt.selected, submitBubbles: true, changeBubbles: true, focusinBubbles: false, deleteExpando: true, noCloneEvent: true, inlineBlockNeedsLayout: false , shrinkWrapBlocks: false, reliableMarginRight: true };
Most of the following are step-by-step tests. The test of BoxModel is more interesting:
div.innerHTML = " "; // Start from scratch div.style.width = div.style.paddingLeft = "1px"; body = document.createElement("body"); body.style.width = 0; body.style.height = 0; body.style.border = 0; body.style.margin = 0; // Set all to 0 body.appendChild(div); document.documentElement.insertBefore(body, document.documentElement.firstChild); support.boxModel = div.offsetWidth === 2; // At this time, the div is nested under the body. The body length, width and height, border and margin are all 0. So the offset of the div should be its own paddingLeft width. If it is incorrect, it means the box mode is incorrect.
Then it is worth noting the bubbling of events. The link to the technical reference article mentioned in the comments has expired. Please search for "Detecting event support without browser sniffing" yourself