使用jquery的load方法載入本地檔案
阿新 • • 發佈:2018-11-11
1. 方法一(圖一):使用chrome瀏覽器,關掉瀏覽器,通過截圖的兩條命令執行chrome瀏覽器,再執行test.html檔案。方法二(圖二):選擇chrome瀏覽器快捷方式,右鍵選擇屬性,再點選快捷方式,在目標"C:\Program Files (x86)\Google\Chrome\Application\chrome.exe"的後面加空格,輸入 --allow-file-access-from-files,點選應用,重新啟動瀏覽器,執行HTML檔案即可。
2. test.html原始碼如下,注意load方法裡的檔案路徑要寫對。
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <script src="jquery/jquery-3.3.1.min.js"> </script> <script> $(document).ready(function(){ $("#btn1").click(function(){ $("#test").load("example/jquery/test.log"); }); }); </script> </head> <body> <p id="test">這裡顯示本地文字內容</p> <button id="btn1" type="button">本地載入</button> </body> </html>