1

これを持つ外部cssファイルにリンクするhtmlファイルがあります

#bottomBar td {
    background-color: red;
}

私のjavascriptでは、ブラウザがIE 10の場合、背景色を赤ではなく青にするものが必要です。これが私がスクリプトに入れようとしたものです

if (Function('/*@cc_on return document.documentMode===10@*/')()) { // this checks if it is IE 10
    $('#bottomBar td').css('background-color', 'blue');
}

これは、まだ何もないため、各bottomBar tdをループしないため、機能しません。私がやりたいのは、#bottomBar td があるかどうかに関係なく、実際の css を変更することだけです。CSS を変更できるようにしたいのです。これを行う方法はありますか?CSS の実際のテキストを変更したいのですが、

$('#bottomBar td').css('background-color', 'blue');

セレクター以降は機能しません

$('#bottomBar td')

存在しない場合、背景色を青から赤に変更しません。制限があり、複数のスタイルシートを使用できず、追加のクラスを追加または削除できないことに注意してください。

4

2 に答える 2

3

次のようなものを試してください:

CSS:

#bottomBar td {
    background-color: red;
}
.ie10 #bottomBar td {
    background-color: blue;
}

js:

if (Function('/*@cc_on return document.documentMode===10@*/')()) { // this checks if it is IE 10
    $('body').addClass('ie10');
}
于 2013-11-04T20:09:00.297 に答える
2

$('body').append('<style>#bottomBar td { background-color: blue; }</style>');

于 2013-11-04T20:05:38.870 に答える