我对 jQuery 很陌生。我需要在某个时间间隔内显示来自数据库的客户推荐。类似于此站点上显示的内容。本站有一个Testimonials容器,在该容器中,从数据库中在特定时间段内一一显示推荐。我在 Google 上尝试了很长时间,但没有成功。如果您知道我可以下载此类脚本的任何链接,那将对我非常有帮助。谢谢。
问问题
230 次
2 回答
2
好吧,你可以在你链接的网站上看看它是如何完成的,就在这里
(function ($) {
$(document).ready(function () {
var el = $("#testimonial");
if (el) {
RotateTestimonial();
setInterval(RotateTestimonial, 20000);
}
});
function RotateTestimonial() {
var pageUrl = "RandomTestimonial.php"
$.ajax({
type: "GET",
url: pageUrl,
cache: false,
success: function (msg) {
$("#testimonial").slideUp('slow').fadeOut(3000, function () {
var el = $("#testimonial"); //Refers to some container tag like <div> or <span> where the random message is to be written.
el.html(msg);
el.slideDown('slow').fadeIn('slow');
});
}
});
}
})(jQuery)
于 2012-05-12T16:40:48.560 回答
1
此代码设置了一个 20 秒的计时器,以将从 YourPageHereReturnsHTML.aspx 返回的 HTML 加载到推荐 div 中。
<div id="testimonial">
</div>
<script>
(function($){
$(document).ready(function(){
var el = $("#testimonial");
if (el){
RotateTestimonial();
setInterval(RotateTestimonial, 20000);
}
});
function RotateTestimonial(){
var pageUrl = "YourPageHereReturnsHTML.aspx"
$.ajax({
type: "GET",
url: pageUrl,
cache:false,
success: function(msg) {
$("#testimonial").slideUp('slow').fadeOut(3000, function (){
var el = $("#testimonial");
el.html(msg);
el.slideDown('slow').fadeIn('slow');
});
}
});
}
})(jQuery)
</script>
于 2012-05-12T17:18:01.007 回答