我一直在和github的坦克合作。https://github.com/AppeonixCreativeLab/waterTank,在进行更新的部分,我找不到一种方法来更改更新的形式,比如不单击,只需等待5秒,然后再次加载,我正在尝试这样的操作
$(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);作者为了这个目的使用了类似的东西,但是通过点击,
$('.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数据库,帮助
发布于 2021-02-05 07:37:11
嗨,欢迎来到stackoverflow。
代码示例的问题是,一旦加载,值将不会更新。
setInterval(function () {
//this function is activate when click and is a number in it
$('.tanque1').waterTank(<?php echo $dato?>);
}, 5000);```前面的代码将从服务器呈现为:
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.
https://stackoverflow.com/questions/66055355
复制相似问题