refactor: refine examples

This commit is contained in:
exaucae 2022-06-17 22:31:32 +00:00
parent 5015fe1d0c
commit ac5f74edc2
2 changed files with 12 additions and 14 deletions

View File

@ -1,8 +0,0 @@
function greetWorld() {
alert("hello world")
}
function salute(name) {
alert("hello: " + name)
}

View File

@ -4,9 +4,16 @@
<meta charset="UTF-8" />
<title>Thymeleaf: Javascript function call</title>
</head>
<script type="text/javascript"
src="../js/functionCall.js">
<script th:inline="javascript">
function greetWorld() {
alert("hello world")
}
function salute(name) {
alert("hello: " + name)
}
</script>
<body>
<header>
<div> Thymeleaf: Javascript function call </div>
@ -14,11 +21,10 @@
<main>
<section class="flex-box">
<button th:onclick="greetWorld()">using no variable</button>
<button th:onclick="'alert(\' 1. static variable used here.\');'">using static variable</button>
<button th:onclick="'alert(\' '1. There are exactly + ${totalStudents} + students'\');'">using inline dynamic variable</button>
<button th:onclick="'javascript:alert(\''2. There are exactly + ${totalStudents} + students'\');'">using javascript:function</button>
<button th:onclick="'alert(\'static variable used here.\');'">using static variable</button>
<button th:onclick="'alert(\'There are exactly ' + ${totalStudents} + ' students\');'">using inline dynamic variable</button>
<button th:onclick="'javascript:alert(\'There are exactly ' + ${totalStudents} + ' students\');'">using javascript:function</button>
<button th:data-name="${student.name}" th:onclick="salute(this.getAttribute('data-name'))">using data attribute</button>
<button th:onclick="@{'salute(' + ${student.name} + ');'}">using @ tag</button>
<button th:onclick="salute([[${student.name}]])">using double brackets</button>
</section>
</main>