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>