jQuery用一些测试来检测浏览器的兼容性,如果报exception,就说明不兼容。当然,这些exception都被包在了try...catch里面。点上 Pause on caught exception 的话,即使被捕获了,浏览器也会在这里暂停。反正是测试,忽略即可。
测试都被包在assert里面
/**
* Support testing using an element
* @param {Function} fn Passed the created div and expects a boolean result
*/
function assert( fn ) {
var div = document.createElement("div");
try {
return !!fn( div );
} catch (e) {
return false;
} finally {
// Remove from its parent by default
if ( div.parentNode ) {
div.parentNode.removeChild( div );
}
// release memory in IE
div = null;
}
}
报错的测试样例是
assert(function( div ) {
// Support: Windows 8 Native Apps
// The type and name attributes are restricted during .innerHTML assignment
var input = doc.createElement("input");
input.setAttribute( "type", "hidden" );
div.appendChild( input ).setAttribute( "name", "D" );
// Support: IE8
// Enforce case-sensitivity of name attribute
if ( div.querySelectorAll("[name=d]").length ) {
rbuggyQSA.push( "name" + whitespace + "*[*^$|!~]?=" );
}
// FF 3.5 - :enabled/:disabled and hidden elements (hidden elements are still enabled)
// IE8 throws error here and will not see later tests
if ( !div.querySelectorAll(":enabled").length ) {
rbuggyQSA.push( ":enabled", ":disabled" );
}
// Opera 10-11 does not throw on post-comma invalid pseudos
div.querySelectorAll("*,:x");
rbuggyQSA.push(",.*:");
});
jQuery用一些测试来检测浏览器的兼容性,如果报exception,就说明不兼容。当然,这些exception都被包在了
try...catch
里面。点上 Pause on caught exception 的话,即使被捕获了,浏览器也会在这里暂停。反正是测试,忽略即可。测试都被包在
assert
里面报错的测试样例是