setinterval

PHP code only runs once inside javascript setInterval

六眼飞鱼酱① 提交于 2019-12-02 22:59:24
问题 I'm just learning PHP and Javascript in a JC class. I have the following for a school project. The following setInterval() runs every 3 seconds, however the embedded PHP code only runs the first time. i.e. newVal gets updated the first time but doesn't change it's value on the following iterations. The script never telnets back into the server to find if the value changed. setInterval(function () { var newVal, mem; <?php $telnet = new PHPTelnet();?>; <?php $result = $telnet->Connect('ip

js timeInterval setInterval无法用clearInterval停止的问题

匿名 (未验证) 提交于 2019-12-02 21:53:52
其实这个问题本身是由于js定时器特性产生的。 clearInterval是根据定时器本身的标识来进行清除的,如果在期间生成了新的interval,并覆盖timer标识对象,旧有的timer定时器对象并不会被停止和清除,而且标识也会丢失导致再也无法被清除,所以写定时器时一定要注意。 下面是一个正确范例: 1 var ajaxObj = null ; //ajax异步加载的对象 2 var timer = null ; 3 4 loadTimerWhenSthIsReady ( params1 ); 5 6 ///param是外部参数,这里仅是举例 7 function loadTimerWhenSthIsReady ( params ) { 8 //一定要先清掉之前的定时器,如果出现两次调用的情况可能导致生成两个定时器。 9 //因为timer本身只是定时器标记并不是定时器对象,所以覆盖并不会让timer停止,旧的timer会一直执行停不下来 10 clearInterval ( timer ); 11 timer = null ; 12 13 timer = setInterval ( function () { 14 if ( ajaxObj != null ) { 15 clearInterval ( timer ); 16 timer = null ; 17 /

前端基础之BOM和DOM

匿名 (未验证) 提交于 2019-12-02 21:53:52
BOM(Browser Object Model)是指浏览器对象模型,它使 JavaScript 有能力与浏览器进行“对话”。 DOM (Document Object Model)是指文档对象模型,通过它,可以访问HTML文档的所有元素。 Window对象是客户端JavaScript最高层对象之一,由于window对象是其它大部分对象的共同祖先,在调用window对象的方法和属性时,可以省略window对象的引用。例如:window.document.write()可以简写成:document.write()。 所有浏览器都支持 window 对象。它表示浏览器窗口。 **如果文档包含框架(frame 或 iframe 标签),浏览器会为 HTML 文档创建一个 window 对象,并为每个框架创建一个额外的 window 对象。* **没有应用于 window 对象的公开标准,不过所有浏览器都支持该对象。* 所有 JavaScript 全局对象、函数以及变量均自动成为 window 对象的成员。 全局变量是 window 对象的属性。全局函数是 window 对象的方法。 一些常用的Window方法: window.innerHeight - 浏览器窗口的内部高度 window.innerWidth - 浏览器窗口的内部宽度 window.open() - 打开新窗口

使用jQuery快速高效制作网页交互特效――02 第二章 JavaScript操作BOM对象

匿名 (未验证) 提交于 2019-12-02 21:53:52
1、 window 对象: 浏览器对象模型(BOM)是javascript的组成之一, 它提供了独立与浏览器窗口进行交换的对象,使用浏览器对象模型可以实现与HTML的交互。 它的作用是将相关的元素组织包装起来,提供给程序设计人员使用,从而降低开发人员的劳动量,提高设计Web页面的能力。 BOM :浏览器对象模型(Browser Object Model):BOM提供了独立于内容的、可以与浏览器窗口进行互动的对象结构; BOM 是一个分层结构: 结构: ★ Window 对象是整个BOM的核心,在浏览器中打开网页后,首先看到是浏览器窗口,即顶层的window对象;其次是网页内容,即document(文档)。 BOM 可实现的功能: 1 ).弹出的浏览器窗口。 2 ).移动、关闭浏览器窗口及调整窗口的大小。 3 ).在浏览器窗口中实现页面的前进、后退功能。 Window 对象也称为浏览器对象。 当浏览器打开HTML文档时,通常会创建一个window对象, 如果文档定义了一个或多个框架, 浏览器将为原始文档创建一个window对象,同时为每个框架另外创建一个window对象。 2、 window 常用的属性: 语法: window. 属性名=”属性值” eg :window.location=”http// www.baidu.com ”, //表示跳转到百度的官方主页。 screen

Checking whether clearInterval has been called?

五迷三道 提交于 2019-12-02 20:10:58
Given this code: bob = setInterval(function, 1000); clearInterval(bob); Is there now a way to know if that interval has been cleared? Currently, I keep track of this myself, by unsetting ' bob ', but I'm curious if my extra line of code is unnecessary: clearInterval(bob); bob = null; if (!bob) itIsCleared(); Thanks! Rich The return value of setInterval is just a unique id you use to pass back to clearInterval . It's not a structured object with any additional information, nor does it get set to null when you call clearTimeout . bob only contains an id of the interval used to clear it. When you

setInterval, this, again

只谈情不闲聊 提交于 2019-12-02 17:23:25
问题 I have a problem in regards to setInterval that i cant figure out. i "know" (...) there is the problem with the scope when calling setInterval or timeout from within an object, but still i cant wrap my head around it. I tried to put my stuff inside an anonymous function, it wont work. This is basicly my problem, simplified to the bare bones: function Scenario(){ var ships = []; this.ini = function(){ for (var i = 0; i < ships.length; i++){ timeoutID1 = setTimeout(ships[i].ding, 1000);

JavaScript: Trigger CSS Transition with window.setTimeout

拜拜、爱过 提交于 2019-12-02 15:52:33
问题 This is (obviously) part of a bigger project, but I am trying to trigger a CS transition on setTimeout . (I know about using CSS animations, but this is not just about repeated transitions). A CSS transition will occur when a property changes. For my own purposes, I use setAttribute as that isolates the behaviour from other class-related stuff, but the behaviour below works the same. Assuming the HTML and other code is in place, here is simplified version: var test=document.querySelector('div

How to pause and resume jquery interval

故事扮演 提交于 2019-12-02 14:30:53
问题 I have made a custom slider with jQuery. For this I have used setInterval function: timer = setInterval(function() {}, 8000); But I cannot pause and resume the interval. I have 2 buttons (play, pause) which I want to use for. Lets say I click pause after 3 sec, and then resume it. So it should stay in that slider for 5 more seconds and then go to the next one and continue 8 seconds each. I have seen this kinda slider with mouseover pause, but can't do it by myself. I have tried this:

setInterval javascript - how to call function

余生颓废 提交于 2019-12-02 11:51:30
Here is the simple example of two similar use of setInterval function: http://codepen.io/anon/pen/MwYOOJ In the first example setInterval function does not work, in the second version where below syntax was used it's working fine. /* This part does not work */ var i = 0; function displayNumber() { i++; $('#result').html(i); } setInterval(displayNumber(), 500); /* This part does work */ var j = 0; function displayNumberOk() { j++; $('#result-ok').html(j); } setInterval(function() { displayNumberOk() }, 500); In specification I can find: setInterval(function,milliseconds,param1,param2,...) Why

PHP code only runs once inside javascript setInterval

血红的双手。 提交于 2019-12-02 10:17:44
I'm just learning PHP and Javascript in a JC class. I have the following for a school project. The following setInterval() runs every 3 seconds, however the embedded PHP code only runs the first time. i.e. newVal gets updated the first time but doesn't change it's value on the following iterations. The script never telnets back into the server to find if the value changed. setInterval(function () { var newVal, mem; <?php $telnet = new PHPTelnet();?>; <?php $result = $telnet->Connect('ip_address','username','password');?>; <?php $telnet->DoCommand('show process memory summary"', $result);?>; <