Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ajax/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如果用户位于文本区域,则可以暂停定时刷新_Javascript_Ajax - Fatal编程技术网

Javascript 如果用户位于文本区域,则可以暂停定时刷新

Javascript 如果用户位于文本区域,则可以暂停定时刷新,javascript,ajax,Javascript,Ajax,好吧,我接受了你给我的答案,然后做了这个,但它不起作用,我可能遗漏了什么 function setusersintext(inout){ var userIsInTextArea = false; if($inout=='in'){ userIsInTextArea = true; }else{ userIsInTextArea = false; } } $(".refreshMe").everyTime(5000,fu

好吧,我接受了你给我的答案,然后做了这个,但它不起作用,我可能遗漏了什么

 function setusersintext(inout){
    var userIsInTextArea = false;
    if($inout=='in'){
       userIsInTextArea = true;
    }else{
       userIsInTextArea = false;
    }
    }

  $(".refreshMe").everyTime(5000,function(i){
      if(!userIsInTextArea) {
        $.ajax({
          url: "refresh-me.php?id=<?php echo $get_id['id']; ?>&user=<?php echo $user; ?    >&user_name=<?php echo $user_name; ?>",
          cache: false,
          success: function(html){
            $("ol#newupdates").prepend(html);

          }
        })
      }
   })
函数setusersintext(inout){
var userIsInTextArea=false;
如果($inout=='in'){
userIsInTextArea=true;
}否则{
userIsInTextArea=false;
}
}
$(“.refreshMe”)。每次(5000,函数(i){
如果(!userIsInTextArea){
$.ajax({
url:“refresh me.php?id=&user=”,
cache:false,
成功:函数(html){
$(“ol#newupdates”).prepend(html);
}
})
}
})
这是区号

<textarea name="comment" class="comment" maxlength="200"  
        id="ctextarea<?php echo $msg_id;?>" 
        onfocus="myFocus(this);setusersintext(in);" 
        onblur="myBlur(this);setusersintext(out);">
  Write a comment...
</textarea>

当用户将焦点设置到文本区域时,只需设置一个标志,然后检查该标志

 var userIsInTextArea = false;

 $('#commentText').focus(function() {
   userIsInTextArea = true;
 });

 $('#commentText').blur(function() {
   userIsInTextArea = false;
 });



  $(".refreshMe").everyTime(5000,function(i){
      if(!userIsInTextArea) {
        $.ajax({
          url: "refresh-me.php?id=<?php echo $get_id['id']; ?>&user=<?php echo $user; ?>&user_name=<?php echo $user_name; ?>",
          cache: false,
          success: function(html){
            $("ol#newupdates").prepend(html);

          }
        })
      }
  })
var userIsInTextArea=false;
$('#commentText')。焦点(函数(){
userIsInTextArea=true;
});
$('#commentText').blur(函数(){
userIsInTextArea=false;
});
$(“.refreshMe”)。每次(5000,函数(i){
如果(!userIsInTextArea){
$.ajax({
url:“refresh me.php?id=&user=&user\u name=”,
cache:false,
成功:函数(html){
$(“ol#newupdates”).prepend(html);
}
})
}
})

非常感谢您这么快的回答。我现在要测试它,并尽快回复。我还有一个问题。。。这是文本区号,或者文本区号中使用的onfocus onblur是否会在顶部触发某些东西much@JudyRobert:您是否需要对此问题进行澄清,或者这是另一个无关的问题?不,这是一个相关的问题,textarea已经有一个无法更改的id,但textarea也有onfocus和onblur,有没有办法检查,基本上我需要知道如何改变或其他工作与对方。谢谢