:あなたは、これがまたここに http://jsbin.com/epuxus/15
アクションで働く見ることができます
isNthChildSupported() ? console.log('yes nth child is supported') : console.log('no nth child is NOT supported');
:使用あなた
function isNthChildSupported(){
var result = false,
test = document.createElement('ul'),
style = document.createElement('style');
test.setAttribute('id', 'nth-child-test');
style.setAttribute('type', 'text/css');
style.setAttribute('rel', 'stylesheet');
style.setAttribute('id', 'nth-child-test-style');
style.innerHTML = "#nth-child-test li:nth-child(even){height:10px;}";
for(var i=0; i<3; i++){
test.appendChild(document.createElement('li'));
}
document.body.appendChild(test);
document.head.appendChild(style);
if(document.getElementById('nth-child-test').getElementsByTagName('li')[1].offsetHeight == 10) {result = true;}
document.body.removeChild(document.getElementById('nth-child-test'));
document.head.removeChild(document.getElementById('nth-child-test-style'));
return result;
}
のためにn番目の子のサポートをjQuery :nth-child
との間に違いがあります。
jQueryの:nth-child
は、私はそこのセレクタをサポートするためにテストさModernizrセレクタプラグインでしたが、私はできません覚えているIE9、クロム、SafariやFirefoxでのjQueryをサポートする任意のブラウザでサポートされが、CSS :nth-child
is supported
正直に言うと、それはブラウザが 'の両方をサポートしていますどちらかと考えるのは非常に合理的です:n番目の子()'と ':最後-child'、またはいずれかをサポートしていません。 – BoltClock
このプラグインを試してみてください。http://selectivizr.com/
cssファイルのみの下に挿入してください! –