使用 javascript 动态变量,如何初始化 jQuery 滑块上的滑动/更改事件?

发布于 2024-11-28 14:31:59 字数 514 浏览 0 评论 0原文

我有: 全局动态变量:

var index=0;

数组:

var arr={ 1:"First", 2:"Second" };

函数:

>var UpdateFunc=函数(值){ arr[索引]=值; }

现在我有一个 jQuery 滑块,其滑块事件初始化如下:

$("#slider").slider({ change: function(evt, ui){ UpdateFunc(ui.value); });

在某些情况下,在调用 sliderchange 之前,VARIABLE 索引已更改,但在调试时,通过 sliderchange 调用的 UpdateFunc 始终为 0(第一次追加)。

所以我的问题是:如何动态初始化 jQuery 滑块的滑动/更改事件,例如在本例中使用动态变量索引?

谢谢并希望尽快收到您的回复。

I have:
a GLOBAL, DYNAMIC variable:

var index=0;

an array:

var arr={ 1:"First", 2:"Second" };

a function:

var UpdateFunc=function(value){ arr[index]=value; };

Now I have a jQuery slider with slider event initialized as below:

$("#slider").slider({ change: function(evt, ui){ UpdateFunc(ui.value); } });

In some case, before sliderchange invoked, VARIABLE index is changed, but as debugging, UpdateFunc invoked through sliderchange, is always 0 (the first time appending).

So my question is: How to initialize slide / change event of jQuery slider DYNAMICALLY, such as with dynamic variable index in this case ?

Thanks and hope to get your responses soon.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

允世 2024-12-05 14:31:59

您可以使用值方法

$('#slider').slider("value", 100);

You can use the value method

$('#slider').slider("value", 100);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文