jQuery加载新的变量 [英] jquery load new vars

查看:116
本文介绍了jQuery加载新的变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是可能的,如果我有一个变量,请使用jquery加载新闻变量并更改这些变量

It´s posible , if i have one var , use jquery for load news vars and change these

例如,如果我有:

var activate_auto="yes";



$("#play").click(function() {

/// load vars
activate_auto="yes";


});


$("#stop").click(function() {

/// load vars
activate_auto="no";


});

完整代码

<script>

var w_ac="900";
var h_ac="295";
var w_ac_col="64";
var n_cols="5";
var margin="3";
var time_ac_change=5000;
var time_ac_effects=2000;
var time_ac_hide_effects=1000;

var ac_activate_auto="si";
var ac_activate_auto_random="no";

var margin=margin*n_cols;
var result=w_ac_col*n_cols+margin;
var final=w_ac-result;


$(function(){




$("#ac_play").click(function() 
{
ac_activate_auto="si";
ac_activate_auto_random="no";
time_ac_change=2000;
});


$("#ac_stop").click(function() 
{
ac_activate_auto="no";
ac_activate_auto_random="no";
time_ac_change=2000000;
});


for (i=1;i<=n_cols;i++)
{

$(".ac_"+i+"").css("width",""+w_ac_col);

}

});


function acordeon(id)
{

$(function(){

for (i=1;i<=n_cols;i++)
{

if (+id==i)
{}
else
{
$(".ac_"+i+"_inf").hide(time_ac_hide_effects);
}

}

$(".ac_"+id+"_inf").css("width",""+final);
$(".ac_"+id+"_inf").show(time_ac_effects).fadeIn(time_ac_effects);

$(".ac_im").css("width",""+final);
$(".ac_im").css("height",""+h_ac);








});





}

</script>


<script>









var starting_slide = n_cols;

function setSlide(i) 
{


acordeon(i);















if (i > 0) {
i--;   
setTimeout( function(){setSlide(i)}, time_ac_change);

}

else 
{
setTimeout( function(){setSlide(starting_slide)}, 1000);
} 

}






if (ac_activate_auto=="si")
{
setSlide(starting_slide);
}






if (ac_activate_auto_random=="si")
{

$(document).ready(function(){

acordeon(1);

var refreshId = setInterval(function(){

var r=Math.floor(Math.random()*n_cols)    

if (r==0)
{
acordeon(1)
}
else
{
acordeon(+r)
}


}, time_ac_change);
});





}

</script>

在这种情况下,当我推送付款或停止时始终有效,但只有一次,如果我推送播放可以播放,但是停止之前没有任何作品,而第一次推送时就相同

In this case works always when i push over pay or stop but only one time , if i push over play works play but no works before stop and the same when the first i push it´s play

我想按停止加载新的变量并播放,而其他时候加载其他变量,我不知道这是否可行,谢谢!

I want push stop load new var and play and other time load the other var , i don´t know if it´s possible , thank´s !

推荐答案

您应该只创建自己的var,不要为其设置值,然后仅在函数内部设置其值.例如:

You should only create your var and don't set a value to it, and then, only set its values inside your functions. Ex.:

var activate_auto; // this is outside your click functions

好吧,现在我不确定您要做什么...以后将在需要时对其进行编辑= \

Ok, now I'm not sure what you want to do... will edit it later if necessary =\

这篇关于jQuery加载新的变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆