我正在尝试在我的HTML正文中插入脚本:
<body>
<script type="text/javascript" src="myFunction.js"></script>可能问题出在路径上,但我找不到我的错误,我更改了100次,下面是我的"myFunction.js":
function myFunction() {
// Declare variables
var input, filter, table, tr, td, i, txtValue;
input = document.getElementById("myInput");
filter = input.value.toUpperCase();
table = document.getElementById("myTable");
tr = table.getElementsByTagName("tr");
var tamano = 0;
// Loop through all table rows, and hide those who don't match the search query
console.log(tr.length);
for (i = 0; i < tr.length; i++) {
td = tr[i].getElementsByTagName("td")[7];
//console.log(td);
if (td) {
txtValue = td.textContent || td.innerText;
if (txtValue.toUpperCase().indexOf(filter) > -1) {
tamano = tamano +1;
tr[i].style.display = "";
} else {
tr[i].style.display = "none";
}
}
}
var list = document.getElementById("capa"); // Get the <ul> element with id="myList"
list.removeChild(list.childNodes[0]);
console.log(tamano);
var capa = document.getElementById("capa");
var h1 = document.createElement("p");
h1.innerHTML = tamano;
capa.appendChild(h1);
}你可以在这里看到我的项目文件夹:

你能帮我找出我做错了什么吗?
谢谢!
发布于 2020-01-08 02:32:54
您的文件myFunction.js位于后端资源的文件夹中,您的Java代码可以访问该文件夹。将禁止浏览器访问此文件,因为这不是存放您的web文件的位置。
您必须将该文件移动到JSP和HTML资源旁边的src/main/webapp (文件系统)。此文件夹中的文件( WEB-INF文件夹除外)可通过浏览器访问。对LOGO.png文件也执行类似的操作。
https://stackoverflow.com/questions/59634131
复制相似问题