私は nettuts で jquery を学ぶための 30 日間と呼ばれる無料の jQuery コースをジェフリー ウェイで行っています。
(function() {
$('html').addClass('js');
var contactForm = {
container: $('#contact'),
init: function() {
$('<button></button>', {
text: 'Contact Me'
})
.insertAfter('article:first-child ')
.on('click', this.show);
},
show: function() {
contactForm.container.slideDown(500);
}
};
contactForm.init();
})();
ウェブサイトの「お問い合わせ」ボタンをクリックすると、基本的にお問い合わせフォームがスライドダウンします。私の質問は次のとおりです。
- 「init」の要点は何ですか?必要ですか?
- jqueryコード全体が変数内にあるのはなぜですか?
.on('click', this.show);
が必要な理由this
を示すコードの文字列this.show
についてcontactForm.container.slideDown(500);
最後に、なぜ単に or と言えないのかというように、なぜ必要なのですcontainer.slideDown(500);
か$('form.contact').slideDown(500);
(ちなみに、スライド ダウンするフォームの ID はcontact
.