#24: N 予備校プログラミング入門の続き、GitHub Pages など
やったこと(Done)
- N 予備校 プログラミング入門 Web アプリコース
- 第 1 章 はじめよう
17. 診断機能の組込み
18. ツイート機能の開発
19. GitHub で Web サイト公開
- 第 2 章 準備しよう
12. GitHub で Web サイト公開
(同内容)
- 第 1 章 はじめよう
第 1 章の続きをやって全て完了させた。理解度チェックの問題も全て回答した。Date.now()
のところだけ理解していなかったけれど今回で覚えた。
わかったこと(Fact)
JavaScript
document.createElement('div')
という形で新しい要素(DOM と同義?)を作成することができる。<既存の要素>.appendChild(<新しい要素>)
という形で既存の要素の中(HTML の内側、子要素)に追加することができる。- 複数の要素やテキストを追加できる
ParentNode.append()
という API も新しくできたそう。
assessmentButton.onclick = doAssessmentAndDisplay; userNameInput.onkeydown = event => { if (event.key === 'Enter') { doAssessmentAndDisplay(); } }
userNameInput.onkeydown
にも同じ動作をさせるためには名前付き関数として独立させる必要があるのかと思ったが、無名関数のままでも以下のようにすることでプロパティ onclick
に代入されている関数を呼び出すことができた。
assessmentButton.onclick = () => { // 省略 } userNameInput.onkeydown = event => { if (event.key === 'Enter') { assessmentButton.onclick(); } }
- 現在の日時を求めるのは
new Date()
で、UNIX 標準時からのミリ秒を求めるのがDate.now()
GitHub Pages
The default publishing source for user and organization sites is the root of the default branch for the repository. The default publishing source for project sites is the root of the
gh-pages
branch. If the default publishing source exists in your repository, GitHub Pages will automatically publish a site from that source.
- リポジトリの settings で theme など、いろいろ設定できるようだ。
参考文献(References)
HTML 要素の追加など
- Document.createElement() - Web APIs | MDN
- Node.appendChild() - Web APIs | MDN
- Node.removeChild() - Web APIs | MDN
- Node.replaceChild() - Web APIs | MDN
- Node.hasChildNodes() - Web APIs | MDN
URI エンコード
setInterval
- Cooperative asynchronous JavaScript: Timeouts and intervals - Learn web development | MDN
- WindowOrWorkerGlobalScope.setInterval() - Web APIs | MDN