【问题标题】:Show only last 10 lines from text file [closed]仅显示文本文件的最后 10 行 [关闭]
【发布时间】:2013-01-20 15:39:05
【问题描述】:

我不是程序员,所以我不知道如何编辑它。

我正在使用我在 stackoverflow 中找到的代码,并且只想显示文本文件的最后 10 行。

<html>
<head>
<script type="text/javascript">
    function loadXMLDoc()
    {
    var xmlhttp;
    if (window.XMLHttpRequest)
      {
      xmlhttp=new XMLHttpRequest();
      }
    xmlhttp.onreadystatechange=function()
      {
      if (xmlhttp.readyState==4 && xmlhttp.status==200)
        {
        document.getElementById("myDiv").innerHTML=xmlhttp.responseText;
        }
      }
    xmlhttp.open("GET","status.txt",true);
    xmlhttp.send();
    }
</script>
</head>
<body>
<script type="text/javascript">
    loadXMLDoc();
</script>
<div id="myDiv">Current Status</div>
<script type="text/javascript">
    setInterval("loadXMLDoc()", 2000);
</script>
</body>
</html>

【问题讨论】:

    标签: php javascript ajax file text


    【解决方案1】:

    这是一种可能的解决方案:

    ... = xmlhttp.responseText.split("\n").slice(-10).join("\n");
    

    【讨论】:

    • 谢谢 :) 现在效果很好 :)
    • @user1994876 不客气。
    猜你喜欢
    • 2020-12-08
    • 2013-02-17
    • 1970-01-01
    • 2020-04-21
    • 1970-01-01
    • 2021-10-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多