1

こいつらを助けて、

ここに、body タグに ID を追加するスクリプトがあります

これが私が見た結果です

<body id="xxx-cat">

以下で使用しているスクリプトで

<script>
$(document).ready(function(){
// Edit xxx-cat to match desired category link id:
$('body').attr("id","xxx-cat");
if ($('body[id]')) {
var bid = $("body").attr("id");
// Keep the next command on one line
$('div.droplinebar li a[class='+bid+']').addClass('current');
}
})
</script>

4ページがあり、次のようにしたいので、ID(1,2,3,4)を作成するにはどうすればよいですか

<body id="1"> for the home page
<body id="2"> for the about
<body id="3"> for the clients
<body id="4"> for the contact

ところで、これは tumblr のカスタム ページです。ここでは PHP を使用できません。

4

2 に答える 2

1

私の質問に対する答えを見つけました

$(function() {
    var pathname = window.location.pathname;
    var getLast = pathname.match(/.*\/(.*)$/)[1];
    var truePath = getLast.replace(".php","");
    if(truePath === '') {
        $('body').attr('id', 'home');
    }
    else {
        $('body').attr('id', truePath);
    }
});

結果

home = <body id="home">
about = <body id="about">
clients = <body id="clients">
contacts = <body id="contacts">
于 2013-02-21T03:32:23.277 に答える
1

あなたの質問を理解しているので、スクリプトを変更することはできますが、ページ自体を変更することはできません (Tumblr にあるためですか?)

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

$(document).ready(function(){
    var bodyId = '1'; // Set to 1, 2, 3, 4 etc    
    $("body").attr('id', bodyId);
    $('div.droplinebar li a.'+bodyId).addClass('current');
});

ただし、コメントで述べたように、ID に番号を使用するだけではいけません。可能であれば、これを修正することを検討してください。

于 2013-02-21T03:00:09.323 に答える