首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >更改坦克的更新类型

更改坦克的更新类型
EN

Stack Overflow用户
提问于 2021-02-05 07:23:48
回答 1查看 18关注 0票数 0

我一直在和github的坦克合作。https://github.com/AppeonixCreativeLab/waterTank,在进行更新的部分,我找不到一种方法来更改更新的形式,比如不单击,只需等待5秒,然后再次加载,我正在尝试这样的操作

代码语言:javascript
复制
 $(document).ready(function() {
        $('.tanque1').waterTank({
            width: 100,
            height:100,
            color: '#72bddb',//color de nuestro liquido
            level:  <?php echo $dato?>,
            tamano:3// tamaño tanque
    });
});
setInterval(function () {
//this function is activate when click and is a number in it
        $('.tanque1').waterTank(<?php echo $dato?>);
            }, 5000);

作者为了这个目的使用了类似的东西,但是通过点击,

代码语言:javascript
复制
$('.waterTankHere1').waterTank({
    width: 420,
    height: 360,
    color: '#8bd0ec',
    level: 83
}).on('click', function(event) {
//this function is activate when click and it has a number in it
        $(this).waterTank(Math.floor(Math.random() * 100) + 0 );
    });

有没有一种方法可以让坦克通过改变点击事件来及时更新?数据来自MySQL数据库,帮助

EN

回答 1

Stack Overflow用户

发布于 2021-02-05 07:37:11

嗨,欢迎来到stackoverflow。

代码示例的问题是,一旦加载,值将不会更新。

代码语言:javascript
复制
setInterval(function () {
//this function is activate when click and is a number in it
        $('.tanque1').waterTank(<?php echo $dato?>);
            }, 5000);```

前面的代码将从服务器呈现为:

代码语言:javascript
复制
setInterval(function () {
//this function is activate when click and is a number in it
        $('.tanque1').waterTank(50); // or whatever value from the server
            }, 5000);```

该函数将每隔5秒从您的代码中调用一次,但它将始终呈现50。你可以使用chrome开发者工具来验证它。

如果您想要从服务器获取值,我建议公开一个端点来只获取值。由于您已经在使用jQuery,因此可以使用call that endpoint with $.get.

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/66055355

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档