参考書:Spring boot プログラミング入門
対象ページ:p173~p175
◆環境
Spring Tool Suite
Version: 3.9.1.RELEASE
Build Id: 201710111105
Platform: Eclipse Oxygen.1a (4.7.1a)
thymeleaf.version 3.0.2.RELEASE
◆問題
上記、参考書のページを参考に実装しましたが、js周りで警告が入り、思うような動作がしません。
◆エラー文
SampleJs.jsファイルから
- Expected an operator and instead saw '/'
- Expected ')' to match '(' from line 6 and instead saw
'100'
- Expected an identifier and instead saw ')'
◆SampleJs.jsファイル
function action() {
var val = document.getElementById("text1").value;
var res = parseInt(val * ((100 + /[[ ${tax} ]]/ ) / 120));
document.getElementById("msg").innerHTML = "include tax: " + res;
}
◆index.html
<!DOCTYPE html> <html xmlns:th="http://www.thymeleaf.org"></html><head> <link th:substituteby="common/head :: common_link" /> <title>top page</title> </head> <body> <h1 th:text ="#{content.title}">Helo page</h1> <p id="msg"></p> <input type="text" id="text1" /> <button onclick="action()">click</button> </body>
◆HeloController.java
@Controller
public class HeloController {
@RequestMapping("/{tax}") public ModelAndView index(@PathVariable int tax, ModelAndView mav) { mav.setViewName("index"); mav.addObject("tax", tax); return mav; }
}
◆確認したこと
SampleJs.jsファイルの/[[ ${tax} ]]/ の箇所がうまく動いていない感じがします。
こちらを仮に「1000000」とかにすると<button onclick="action()">click</button>で
設定している箇所が動くのですが、/[[ ${tax} ]]/に戻した場合に、やはり動作しない形になります。
大変申し訳ございませんが、ご教授お願いします。
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。