[英]Call javascript function in thymeleaf
I need to call a javascript function inn thymeleaf and I am getting an error as function is not defined. 我需要调用javascript函数inn thymeleaf,但由于未定义函数,因此出现错误。 Here's my code 这是我的代码
<div class="input-field col s6 m6">
<input id="isbn" name="isbn" type="text" class="validate" />
<label for = "isbn">Enter ISBN Code</label>
</div>
<div class="input-field col s6 m6">
<button id="submitCode" class="btn waves-effect waves-light col m4" th:onclick="'javascript:myFunction();'" value="data">ISBN Data</button>
</div>
Javascript Code JavaScript代码
function myFunction()
{
var isbn = document.getElementById('isbn').value;
alert(isbn);
var xmlhttp = new XMLHttpRequest();
var url = "https://www.googleapis.com/books/v1/volumes?q=isbn:" + isbn;
xmlhttp.onreadystatechange = function()
{
if (xmlhttp.readyState == 4 && xmlhttp.status == 200)
{
var x = JSON.parse(xmlhttp.responseText);
callback(x);
}
};
xmlhttp.open("GET", url, true);
xmlhttp.send();
}
function callback(x)
{
//do things with your data here
alert(JSON.stringify(x));
console.log(x);
}
也许您应该尝试th:onclick="'myFunction();'"
您可以使用Thymeleaf引用此链接Javascript函数调用
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.