gpt4 book ai didi

javascript - 将函数从 jQuery 转换为 Mootools

转载 作者:行者123 更新时间:2023-12-02 18:13:56 25 4
gpt4 key购买 nike

我们有这段代码来刷新我们拥有的 DIV,包括一个用于请求数据的文件。当前功能运行良好,但我们需要 mootools 迁移。

JS 代码:

<script>
jQuery.noConflict();
(function(jQuery) {
jQuery(function() {
jQuery(document).ready(function() {
// First initial refresh onLoad
jQuery(".wall_actions").fadeOut("fast").load("auto-refresh.php").fadeIn("fast");
// Use now with Interval - 10 seconds
var refreshId = setInterval(function() {
jQuery(".wall_actions").fadeOut("fast").load('auto-refresh.php').fadeIn("fast");
}, 5000);

jQuery.ajaxSetup({
cache: false
});

});
});
})(jQuery);
</script>

<div class="wall_actions">
<!-- other code -->
</div>

我们尝试使用此方法进行迁移,但没有成功。

<script language="javascript">
var request = new Request({
url: 'auto-refresh.php',
method: 'get',
update: 'refresh-me',
onComplete: function(response) {
$('.wall_actions').set('html',response);
}
})

var doRefresh = function() {
request.send();
};

doRefresh.periodical(5000);
</script>

自动刷新.php

<?php
$page = "auto-refresh";
include "header.php";

$actions_array = $actions->actions_display(0, $setting['setting_actions_actionsperuser']);
$smarty->assign_by_ref('actions', $actions_array);
include "footer.php";
?>

我们如何使用 jQuery 函数来发出请求,但是使用 MooTools?

最佳答案

您很接近,实际上您只是错过了$$

$ 是一个 ID 选择器,您应该使用 document.getElements('.wall_actions')$$('.wall_actions'); 而不是 $('.wall_actions').set('html',response); 中的一美元。

<小时/>

如果您想要淡出/淡入,可以尝试以下操作:

var request = new Request({
url: 'auto-refresh.php',
method: 'get',
update: 'refresh-me',
onComplete: function (response) {
el.set('tween', {
onComplete: function () {
el.set('html', response ).fade('in')
}
});
el.fade('out');
}
})

var doRefresh = function () {
request.send();
};

window.addEvent('domready', function () {
el = $$('.wall_actions');
doRefresh.periodical(5000);
});

我不知道你的html,但看看这个Fiddle .
(顺便说一句,仔细检查你的 php 是否回显某些内容)

关于javascript - 将函数从 jQuery 转换为 Mootools,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19473954/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com