簡體   English   中英

無法在 Netbeans 中讀取腳本 js 文件

[英]Cannot read script js file in Netbeans

我正在嘗試在我的 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);

        }

你可以在這里看到我的項目文件夾:

項目文件夾

你能幫我找出我做錯了什么嗎?

謝謝!

您的文件myFunction.js位於后端資源文件夾內,您的 Java 代碼可以訪問該文件夾。 瀏覽器訪問將禁用此文件,因為這不是您的 Web 文件的位置。

您必須將該文件移動到 JSP 和 HTML 資源旁邊的src/main/webapp (文件系統)。 此文件夾中的文件,除WEB-INF文件夾外,均可通過瀏覽器訪問。 對 LOGO.png 文件也做類似的處理。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM