-2

クラスの css を変更するアクションをスクリプトに追加したい

document.write( 'DIV STYLE='display;none;); />' ) } 私の最初のアイデアでしたが、うまくいかないようです

    if (location.href.indexOf( "/smispage""/tpfpage""/client_images_new""/client_images_list" ) > -1) {
document.write( '<base target="_blank" />' );
     }

それに追加する

    if (location.href.indexOf( "/smispage""/tpfpage""/client_images_new""/client_images_list" ) > -1) {
document.write( '<base target="_blank" />' ); document.write( 'DIV STYLE='display;none;); />' ) 
    }

体は

     <div class="headerlogo"> Serious Photography </div>
     <div> Serious Photography 2 </div>
4

2 に答える 2

0

のご使用はお避けくださいdocument.write。理由を説明するリンクを次に示します。の引数にindexOfも無効な構文が含まれています。HTML base もスタイルの適用とは関係なく、 HTML/CSS 構文が正しくなく、スタイルをクラス 'DIV STYLE='display;none;); />'に適用しても効果がありません。headerlogo

これは、まだ存在しないクラスや ID にスタイル タグを追加する場合に便利です。

if (location.href.indexOf(
       "/smispage/tpfpage/client_images_new/client_images_list") > -1
) {
    var style = document.createElement('style');
    style.type = 'text/css';
    style.appendChild(document.createTextNode('.headerlogo{display:none;}'));
    document.getElementsByTagName('head')[0].appendChild(style);
}
于 2013-01-30T20:56:13.573 に答える
0

これはちょっと難しい質問ですが、現在のページを確認したい場合は、

window.location.href 

文字列を照合するための条件付きチェックにより、新しいスタイルを追加するかどうかを決定できます。クラスをIDに変更します。

それからあなたはすることができます

document.getElementById('headerlogo').style.display = 'none';

個人的には、SIZZLE または jQuery を使用してセレクターを簡単にします。

$('.headerlogo').css('display', 'none');
于 2013-01-30T20:50:38.353 に答える