自动刷新div,当textarea选择停止刷新div时

时间:2016-02-27 07:03:26

标签: javascript php websocket

我创建了一个div块并将其设置为每5秒刷新一次并且它还包含textarea所以我在java脚本中创建另一个函数以停止刷新,当我从textarea失去焦点时它会自动刷新div,但是问题是,当我重新聚焦文本区域时,它不会停止自动刷新

    <div id="statusarea">
   <div id="status_20" class="status_boxes">
      <div><b>Posted by <a href="user.php?u=mtest">mtest</a> 2016-02-23 14:28:47:</b> <span id="sdb_20"><a

     href="#" onclick="return false;" onmousedown="deleteStatus('20','status_20');" title="DELETE THIS STATUS AND ITS REPLIES">delete status</a></span> &nbsp; &nbsp; <br>sdxcscsc</div>
          <div id="reply_21" class="reply_boxes">
             <div><b>Reply by <a href="user.php?u=mtest">mtest</a> 2016-02-23 14:29:00:</b> <span id="srdb_21"><a href="#" onclick="return false;" onmousedown="deleteReply('21','reply_21');" title="DELETE THIS COMMENT">remove</a></span><br>SWSQQ</div>
          </div>
          <div id="reply_22" class="reply_boxes">
             <div><b>Reply by <a href="user.php?u=mtest">mtest</a> 2016-02-26 23:23:29:</b> <span id="srdb_22"><a href="#" onclick="return false;" onmousedown="deleteReply('22','reply_22');" title="DELETE THIS COMMENT">remove</a></span><br>asdfvfdfdd</div>
          </div>
       </div>
       <textarea id="replytext_20" class="replytext" onfocus="onfocusstoptimer()" onblur="onblurstarttimer()" onkeyup="statusMax(this,250)" placeholder="write a comment here"></textarea>
       <button id="replyBtn_20" onclick="replyToStatus(20,'mtest','replytext_20',this)">Reply</button>
       <div id="status_15" class="status_boxes">
          <div><b>Posted by <a href="user.php?u=mtest2">mtest2</a> 2016-02-22 01:56:09:</b> <span id="sdb_15"><a href="#" onclick="return false;" onmousedown="deleteStatus('15','status_15');" title="DELETE THIS STATUS AND ITS REPLIES">delete status</a></span> &nbsp; &nbsp; <br>sdfdsf</div>
       </div>
       <textarea id="replytext_15" class="replytext" onfocus="onfocusstoptimer()" onblur="onblurstarttimer()" onkeyup="statusMax(this,250)" placeholder="write a comment here"></textarea>
       <button id="replyBtn_15" onclick="replyToStatus(15,'mtest','replytext_15',this)">Reply</button>
       <div id="status_3" class="status_boxes">
          <div><b>Posted by <a href="user.php?u=mtest">mtest</a> 2016-02-17 12:35:57:</b> <span id="sdb_3"><a href="#" onclick="return false;" onmousedown="deleteStatus('3','status_3');" title="DELETE THIS STATUS AND ITS REPLIES">delete status</a></span> &nbsp; &nbsp; <br>&lt;script&gt;alert("sdade");&lt;/script&gt;</div>
          <div id="reply_4" class="reply_boxes">
             <div><b>Reply by <a href="user.php?u=mtest">mtest</a> 2016-02-17 13:23:46:</b> <span id="srdb_4"><a href="#" onclick="return false;" onmousedown="deleteReply('4','reply_4');" title="DELETE THIS COMMENT">remove</a></span><br>sfdsf</div>
          </div>
          <div id="reply_5" class="reply_boxes">
             <div><b>Reply by <a href="user.php?u=mtest">mtest</a> 2016-02-17 13:23:59:</b> <span id="srdb_5"><a href="#" onclick="return false;" onmousedown="deleteReply('5','reply_5');" title="DELETE THIS COMMENT">remove</a></span><br>sdfff</div>
          </div>
       </div>
       <textarea id="replytext_3" class="replytext" onfocus="onfocusstoptimer()" onblur="onblurstarttimer()" onkeyup="statusMax(this,250)" placeholder="write a comment here"></textarea>
       <button id="replyBtn_3" onclick="replyToStatus(3,'mtest','replytext_3',this)">Reply</button>
       <div id="status_2" class="status_boxes">
          <div><b>Posted by <a href="user.php?u=mtest">mtest</a> 2016-01-28 11:56:09:</b> <span id="sdb_2"><a href="#" onclick="return false;" onmousedown="deleteStatus('2','status_2');" title="DELETE THIS STATUS AND ITS REPLIES">delete status</a></span> &nbsp; &nbsp; <br>hello</div>
          <div id="reply_16" class="reply_boxes">
             <div><b>Reply by <a href="user.php?u=mtest2">mtest2</a> 2016-02-23 14:23:22:</b> <span id="srdb_16"><a href="#" onclick="return false;" onmousedown="deleteReply('16','reply_16');" title="DELETE THIS COMMENT">remove</a></span><br>sdsds</div>
          </div>
          <div id="reply_17" class="reply_boxes">
             <div><b>Reply by <a href="user.php?u=mtest2">mtest2</a> 2016-02-23 14:23:51:</b> <span id="srdb_17"><a href="#" onclick="return false;" onmousedown="deleteReply('17','reply_17');" title="DELETE THIS COMMENT">remove</a></span><br>dddfdf</div>
          </div>
          <div id="reply_18" class="reply_boxes">
             <div><b>Reply by <a href="user.php?u=mtest2">mtest2</a> 2016-02-23 14:23:59:</b> <span id="srdb_18"><a href="#" onclick="return false;" onmousedown="deleteReply('18','reply_18');" title="DELETE THIS COMMENT">remove</a></span><br>ds</div>
          </div>
          <div id="reply_19" class="reply_boxes">
             <div><b>Reply by <a href="user.php?u=mtest2">mtest2</a> 2016-02-23 14:24:18:</b> <span id="srdb_19"><a href="#" onclick="return false;" onmousedown="deleteReply('19','reply_19');" title="DELETE THIS COMMENT">remove</a></span><br>efe</div>
          </div>
       </div>
       <textarea id="replytext_2" class="replytext" onfocus="onfocusstoptimer()" onblur="onblurstarttimer()" onkeyup="statusMax(this,250)" placeholder="write a comment here"></textarea>
       <button id="replyBtn_2" onclick="replyToStatus(2,'mtest','replytext_2',this)">Reply</button>
    </div>

上面的整个div是echo $ statuslist,脚本是

function statuslist(){
        var slist = "<?php echo $statuslist; ?>";

        document.getElementById("statusarea").innerHTML = slist;
        }
function onfocusstoptimer(){
        clearTimeout (myVar);
        clearTimeout (myVar1);
        }
function onblurstarttimer(){
        var myVar1 =setInterval (statuslist, 2000);
        }
var myVar =setInterval (statuslist, 2000);

我尝试在onfocusstoptime函数上使用clearTimeout(myVar1)来显示错误 请帮帮我,也想知道我会在这上面使用websocket 我正在使用php&amp; javascript。

1 个答案:

答案 0 :(得分:0)

你不应该在这里使用clearInterval而不是clearTimeout吗?

myVar是使用setInterval设置的,所以我认为应该使用clearInterval来停止它。