コードの最初の部分は次のとおりです。
$('ul li').click(function(){ //when an <li> is clicked
$('ul .clicked').removeClass('clicked'); // remove .clicked class from any other <li>'s inside a <ul>
$(this).addClass('clicked'); // add .clicked class to the clicked <li> ($(this))
screen = $(this).attr('id'); // screen = the clicked elements' id
screen = "#" + screen; // screen = the clicked elements' id with a # infront of it
$(screen).screenSlide(); // is basically = $('#elementsID').screenSlide();, correct?
});
私が書いた以前の関数では、セレクターとして画面を渡す代わりに、最後のステップを除いてまったく同じことをしたので、奇妙ですそれをセレクターとして使用すると、機能しました。しかし、先に進むと、screenSlide は
function screenSlide(){ // $(this) should = an <li> who's id is screen
var test = $(this).attr('class');
alert(test);
$(this).addClass('current'); // add the .current class to $(this), which should be an <li>
$(this).slideDown();
};
今、アラート テストは何も警告しなかったので、CSS セレクターとしての画面の受け渡しがうまくいかなかったと推測しています。ご覧のとおり、screenSlide 関数は $(this) < li > にクラスを追加してからスライドアップすることになっています。
何が問題なのですか?