当我想呈现包含 js 文件上的脚本链接的 html 文件时出现错误。但是当我加载页面时,我收到此错误:
Started GET "/views/script.js" .... Returning 404
我的文件夹是这样的
|--todolist
|--main.go
|--views/
|--index.html
|--script.js
main.go
package main
import (
"github.com/zenazn/goji"
"html/template"
"net/http"
)
func renderHTMLPage(w http.ResponseWriter, path string) {
t, err := template.ParseFiles(path)
if err != nil {
panic(err)
}
t.Execute(w, nil)
}
func Index(w http.ResponseWriter, r *http.Request) {
renderHTMLPage(w, "./views/index.html")
}
func main() {
goji.Get("/", Index)
goji.Serve()
}
视图/index.html
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Le titre du document</title>
</head>
<body>
<script src="https://code.jquery.com/jquery-1.10.2.js"></script>
<script src="script.js"></script>
<h1>To-Do List </h1>
<ul id="todolist">
<li> Hello <button>Delete</button></li>
<li> Wesh <button>Delete</button></li>
</ul>
<input type="text" id="new-text" /><button id="add">Add</button>
</body>
</html>
视图/script.js
function addListItem() {
var text = $('#new-text').val()
if (text != "") {
$('#todolist').append('<li>'+text+'<button id="dede" name=\"' + i + '\">Delete</button></li>')
}
$('#new-text').val("")
}
function deleteItem() {
$(this).parent().remove()
}
$(function() {
$('#add').on('click', addListItem);
$("#todolist").on("click", "#dede", deleteItem)
});
我怎样才能让它正确加载 js 文件?
创建仅使用 jquery/javascript 和 golang api 架构的应用程序的最佳方法是什么?
UYOU
繁星点点滴滴
相关分类