jQuery:如何将滑块中的值收集到以 id 作为键的简单对象中
我有几个 jQuery UI 滑块,我想收集它们的值。以为这将是一个简单的任务,但是当我要做的时候,我被卡住了,不太确定该做什么了:p
我想要最终得到的对象应该看起来像这样:
{
a: 80,
b: 90,
c: 20,
...
}
我可以像这样手动完成this:
var values = {
a: $('#a').slider('value'),
b: $('#b').slider('value'),
c: $('#c').slider('value'),
...
};
但这有点乏味,特别是当我需要添加、删除或重命名时。希望我可以对地图或每个功能或类似的东西做一些事情,但我无法弄清楚。有人有一些聪明的想法吗?
I have several jQuery UI Sliders and I want to collect their values. Thought it would be a simple task, but when I was going to do it I got stuck and not quite sure what to do anymore :p
The object I would like to end up with should look something like this:
{
a: 80,
b: 90,
c: 20,
...
}
I can do it manually like this:
var values = {
a: $('#a').slider('value'),
b: $('#b').slider('value'),
c: $('#c').slider('value'),
...
};
But that's a bit tedious, especially if I need to add or remove or rename. Was hoping I could do something with the map or each function or something like that, but I can't figure it out. Anyone have some clever ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以使用它分配的类
.ui-slider
并循环获取/存储值,如下所示:您可以在此处查看演示,尽量保持简短:)
You can use the class it assigns,
.ui-slider
and loop through to get/store values, like this:You can view a demo here, tried to keep it short :)