File tree 2 files changed +13
-7
lines changed
src/main/scala/tutorial/webapp
2 files changed +13
-7
lines changed Original file line number Diff line number Diff line change 5
5
< title > The Scala.js Tutorial</ title >
6
6
</ head >
7
7
< body >
8
- < button id ="click-me-button " type ="button " onclick ="addClickedMessage() ">
9
- Click me!
10
- </ button >
11
-
12
8
<!-- Include Scala.js compiled code -->
13
9
< script type ="text/javascript " src ="./target/scala-2.13/scala-js-tutorial-fastopt/main.js "> </ script >
14
10
</ body >
Original file line number Diff line number Diff line change 1
1
package tutorial .webapp
2
2
3
- import scala .scalajs .js .annotation .JSExportTopLevel
4
-
5
3
import org .scalajs .dom
6
4
import org .scalajs .dom .document
7
5
8
6
object TutorialApp {
9
7
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
+
10
21
appendPar(document.body, " Hello World" )
11
22
}
12
23
@@ -16,7 +27,6 @@ object TutorialApp {
16
27
targetNode.appendChild(parNode)
17
28
}
18
29
19
- @ JSExportTopLevel (" addClickedMessage" )
20
30
def addClickedMessage (): Unit = {
21
31
appendPar(document.body, " You clicked the button!" )
22
32
}
You can’t perform that action at this time.
0 commit comments