亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

使用本地版本時丟失BootStrap格式

使用本地版本時丟失BootStrap格式

Go
慕斯709654 2021-04-09 17:14:22
我正在寫我的第一個Web服務器,所以不要討厭。我在BootStrap中使用Golang和HTML。該程序最終將在小型設備上的Raspberry Pi上運行。因此,我認為最好使用BootStrap的下載版本而不是CDN版本,對嗎?但是,當我這樣做時,頁面上的按鈕會丟失其格式。這是我使用CDN版本的HTML代碼:<!DOCTYPE html><html><head>  <title>Cacophonator Setup</title>  <meta charset="utf-8">  <meta name="viewport" content="width=device-width, initial-scale=1">  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script></head><body><div class="container">  <h2>Cacophonator Setup</h2>  <div class="col-sm-12">        <!-- <a href="\CameraPositioning\" class="btn btn-primary" type="button">Camera Positioning</a> -->    <button type="button" class="btn btn-primary" onclick="location.href='camera-positioning.html'">Camera Positioning</button>  </div>  <div class="col-sm-12">        <button type="button" class="btn btn-primary" onclick="location.href='3G-connectivity.html'">3G Connectivity</button>  </div>          <div class="col-sm-12">      <button type="button" class="btn btn-primary" onclick="location.href='API-server.html'">API Server</button>  </div>  <div class="col-sm-12">    <button type="button" class="btn btn-primary" onclick="location.href='network-interfaces.html'">Network Interfaces</button>  </div></body></html>我只更改了2行,以便使用(或嘗試使用)本地BootStrap CSS和JS。我從Go中這樣稱呼它:http.HandleFunc("/", managementinterface.IndexHandler)log.Fatal(http.ListenAndServe(":8080", nil))而IndexHandler就像這樣:func IndexHandler(w http.ResponseWriter, r *http.Request) {    t, _ := template.ParseFiles("../html/index.html")    t.Execute(w, "")}最后一點:CDN版本是3.3.7,我下載的版本是4.1.1而且,如果我查看本地BootStrap CSS文件,也可以看到以下內容:.btn-primary {  color: #fff;  background-color: #007bff;  border-color: #007bff;}我想要的是哪種樣式。任何幫助表示贊賞,謝謝。
查看完整描述

2 回答

?
aluckdog

TA貢獻1847條經驗 獲得超7個贊

您實際上是從Go代碼中提供JS和CSS代碼嗎?如果不是,則您的瀏覽器正在向Go HTTP服務器詢問資源,但是卻不知道您在說什么(如果您在瀏覽器中查看開發者控制臺,它將向您顯示對這些文件請求的404響應。


您可能需要做類似的事情(假設您將CSS和JS放在稱為資產的目錄中)


cssFs := http.FileServer(http.Dir("/home/user/www/assets/css"))

http.Handle("/css", fs)

jsFs := http.FileServer(http.Dir("/home/user/www/assets/js"))

http.Handle("/js", fs)

有關更多信息,請訪問http.FileServer


查看完整回答
反對 回復 2021-04-19
  • 2 回答
  • 0 關注
  • 362 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號