Skip to content

Commit 932cbe9

Browse files
gzm0sjrd
authored andcommitted
Step 4: Reacting on User Input
1 parent d55ab22 commit 932cbe9

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

scalajs-tutorial-fastopt.html

+4
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@
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+
812
<!-- Include Scala.js compiled code -->
913
<script type="text/javascript" src="./target/scala-2.13/scala-js-tutorial-fastopt/main.js"></script>
1014
</body>

src/main/scala/tutorial/webapp/TutorialApp.scala

+7
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package tutorial.webapp
22

3+
import scala.scalajs.js.annotation.JSExportTopLevel
4+
35
import org.scalajs.dom
46
import org.scalajs.dom.document
57

@@ -13,4 +15,9 @@ object TutorialApp {
1315
parNode.textContent = text
1416
targetNode.appendChild(parNode)
1517
}
18+
19+
@JSExportTopLevel("addClickedMessage")
20+
def addClickedMessage(): Unit = {
21+
appendPar(document.body, "You clicked the button!")
22+
}
1623
}

0 commit comments

Comments
 (0)