Skip to content

Commit 39c0517

Browse files
committed
refactor: refine examples
1 parent 26a8c00 commit 39c0517

File tree

2 files changed

+12
-14
lines changed

2 files changed

+12
-14
lines changed

spring-web-modules/spring-thymeleaf/src/main/webapp/WEB-INF/js/functionCall.js

Lines changed: 0 additions & 8 deletions
This file was deleted.

spring-web-modules/spring-thymeleaf/src/main/webapp/WEB-INF/views/functionCall.html

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,27 @@
44
<meta charset="UTF-8" />
55
<title>Thymeleaf: Javascript function call</title>
66
</head>
7-
<script type="text/javascript"
8-
src="../js/functionCall.js">
7+
<script th:inline="javascript">
8+
function greetWorld() {
9+
alert("hello world")
10+
}
11+
12+
function salute(name) {
13+
alert("hello: " + name)
14+
}
915
</script>
16+
1017
<body>
1118
<header>
1219
<div> Thymeleaf: Javascript function call </div>
1320
</header>
1421
<main>
1522
<section class="flex-box">
1623
<button th:onclick="greetWorld()">using no variable</button>
17-
<button th:onclick="'alert(\' 1. static variable used here.\');'">using static variable</button>
18-
<button th:onclick="'alert(\' '1. There are exactly + ${totalStudents} + students'\');'">using inline dynamic variable</button>
19-
<button th:onclick="'javascript:alert(\''2. There are exactly + ${totalStudents} + students'\');'">using javascript:function</button>
24+
<button th:onclick="'alert(\'static variable used here.\');'">using static variable</button>
25+
<button th:onclick="'alert(\'There are exactly ' + ${totalStudents} + ' students\');'">using inline dynamic variable</button>
26+
<button th:onclick="'javascript:alert(\'There are exactly ' + ${totalStudents} + ' students\');'">using javascript:function</button>
2027
<button th:data-name="${student.name}" th:onclick="salute(this.getAttribute('data-name'))">using data attribute</button>
21-
<button th:onclick="@{'salute(' + ${student.name} + ');'}">using @ tag</button>
2228
<button th:onclick="salute([[${student.name}]])">using double brackets</button>
2329
</section>
2430
</main>

0 commit comments

Comments
 (0)