File tree Expand file tree Collapse file tree 2 files changed +13
-7
lines changed
src/main/scala/tutorial/webapp Expand file tree Collapse file tree 2 files changed +13
-7
lines changed Original file line number Diff line number Diff line change 55 < title > The Scala.js Tutorial</ title >
66 </ head >
77 < body >
8- < button id ="click-me-button " type ="button " onclick ="addClickedMessage() ">
9- Click me!
10- </ button >
11-
128 <!-- Include Scala.js compiled code -->
139 < script type ="text/javascript " src ="./target/scala-2.13/scala-js-tutorial-fastopt/main.js "> </ script >
1410 </ body >
Original file line number Diff line number Diff line change 11package tutorial .webapp
22
3- import scala .scalajs .js .annotation .JSExportTopLevel
4-
53import org .scalajs .dom
64import org .scalajs .dom .document
75
86object TutorialApp {
97 def main (args : Array [String ]): Unit = {
8+ document.addEventListener(" DOMContentLoaded" , { (e : dom.Event ) =>
9+ setupUI()
10+ })
11+ }
12+
13+ def setupUI (): Unit = {
14+ val button = document.createElement(" button" )
15+ button.textContent = " Click me!"
16+ button.addEventListener(" click" , { (e : dom.MouseEvent ) =>
17+ addClickedMessage()
18+ })
19+ document.body.appendChild(button)
20+
1021 appendPar(document.body, " Hello World" )
1122 }
1223
@@ -16,7 +27,6 @@ object TutorialApp {
1627 targetNode.appendChild(parNode)
1728 }
1829
19- @ JSExportTopLevel (" addClickedMessage" )
2030 def addClickedMessage (): Unit = {
2131 appendPar(document.body, " You clicked the button!" )
2232 }
You can’t perform that action at this time.
0 commit comments