あるときに、ここに私のコードは^機能doesntの仕事私のコードは次のようになると変数は、私は奇妙な問題になった最初の
$(document).ready(function(){
$(".switch-content div:first-child").fadeIn();
$(".switch-content div:first-child").toggleClass("switch-active");
$(".switch-menu ul li").click(function(){
var clicked = $(this).index()+1;
$(this).parent().find("li.switch-active").toggleClass("switch-active");
$(this).toggleClass("switch-active");
$(this).parent().parent().parent().find(".switch-content div.switch-active").fadeOut();
$(this).parent().parent().parent().find(".switch-content div.switch-active").toggleClass("switch-active");
$(this).parent().parent().parent().find(".switch-content div:nth-child("+clicked+")").delay(200).toggleClass("switch-active");
$(this).parent().parent().parent().find(".switch-content div:nth-child("+clicked+")").delay(200).fadeIn();
});
})
var anchor = window.location.hash.substring(1);
var linked = $("#"+anchor).index()+1;
で、これは
の作品、すべてが正常に動作しますが、私最初の場所で変数を移動すると、私のjavascriptは動作を停止します。
var anchor = window.location.hash.substring(1);
var linked = $("#"+anchor).index()+1;
$(document).ready(function(){
$(".switch-content div:first-child").fadeIn();
$(".switch-content div:first-child").toggleClass("switch-active");
$(".switch-menu ul li").click(function(){
var clicked = $(this).index()+1;
$(this).parent().find("li.switch-active").toggleClass("switch-active");
$(this).toggleClass("switch-active");
$(this).parent().parent().parent().find(".switch-content div.switch-active").fadeOut();
$(this).parent().parent().parent().find(".switch-content div.switch-active").toggleClass("switch-active");
$(this).parent().parent().parent().find(".switch-content div:nth-child("+clicked+")").delay(200).toggleClass("switch-active");
$(this).parent().parent().parent().find(".switch-content div:nth-child("+clicked+")").delay(200).fadeIn();
});
^このdoesntの仕事
誰もがなぜ知っていますか?それは私には意味がありません。そして私のコードはもっとシンプルにできることを知っています。私はそれに取り組んでいます。
はありがとうと素敵な一日
コンソールのエラーを確認しましたか? – Rajesh
私はコンソールをチェックしていて、珍しいことはありませんでした。また、あなたが最も近いことを意味しています、ありがとう。 ) – Kyrbi
()。parent()。parent()。parent()はclosest()を使用し、リンク変数はページが完全にロードされていない場合はNULLになる可能性があります。 – madalinivascu