简体   繁体   English

无法在 Netbeans 中读取脚本 js 文件

[英]Cannot read script js file in Netbeans

I am trying to insert script in the body of my HTML:我正在尝试在我的 HTML 正文中插入脚本:

<body>
    <script type="text/javascript" src="myFunction.js"></script>

Probably the problem is the path, but I am not able to find my error, I change it 100 of the times, here is my "myFunction.js":问题可能出在路径上,但我找不到我的错误,我更改了 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);

        }

And you can see here my project folder:你可以在这里看到我的项目文件夹:

项目文件夹

Can you help me to find out what I am doing wrong?你能帮我找出我做错了什么吗?

Thanks!谢谢!

Your file myFunction.js is inside the folder for backend resources, where your Java code can access.您的文件myFunction.js位于后端资源文件夹内,您的 Java 代码可以访问该文件夹。 This file will be disabled for browser access because this isn't the place for your web files.浏览器访问将禁用此文件,因为这不是您的 Web 文件的位置。

You have to move that file to src/main/webapp (file system) next to your JSP and HTML resources.您必须将该文件移动到 JSP 和 HTML 资源旁边的src/main/webapp (文件系统)。 Files in this folder, except for WEB-INF folder, are available through browsers.此文件夹中的文件,除WEB-INF文件夹外,均可通过浏览器访问。 Do similar with LOGO.png file as well.对 LOGO.png 文件也做类似的处理。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM