HTML代碼
<textarea id = "div1" style="width:1650px; height:740px" readonly> </textarea>
JS代碼
這里試用了兩種方法都可以
1.ajax
mounted() { document.getElementById('div1').innerHTML = '讀取中...'; $(document).ready(function(){ $.ajax({async: true, url:"dhcpdlog",success:function(result){ $("#div1").html(result); }}); }); }
2.load
mounted() { // this.getInfo() document.getElementById('div1').innerHTML = '讀取中...'; $(document).ready(function(){ $("#div1").load("/arplog"); }); }
然后效果如圖所示
讀取中
讀取完畢
測試:
1.代碼
<!DOCTYPE html> <html> <body> <textarea id="div1" style="width:1650px; height:740px" readonly> </textarea> <script src="https://cdn.staticfile.org/jquery/1.10.2/jquery.min.js"></script> <script type="text/javascript"> document.getElementById('div1').innerHTML = '讀取中...'; $(document).ready(function () { $.ajax({ async: true, url: "text.txt", success: function (result) { $("#div1").html(result); } }); }); </script> </body> </html>
2.test.txt
3.文件結構
4.使用http-server啟動一個服務后訪問(詳細參考:https://www.cnblogs.com/nolaaaaa/p/9126385.html)
參考:https://blog.csdn.net/princek123/article/details/82762083?utm_source=blogxgwz6