使用 jQuery Mobile 动态更改翻转开关的值
我正在使用 jQuery Mobile,并将一些设置保存在 cookie 中。当设置页面重新加载时,我读取 cookie 以设置所有值。我在设置翻转切换开关时遇到问题。大多数元素只需要触发 keyup
或 changed
事件,但我不确定翻转切换如何从选择框中获取其值。有什么想法吗?
I'm working with jQuery Mobile, and I save some settings in a cookie. When the settings page is reloaded, I read the cookie to set all the values. I'm having trouble setting the flip toggle switch. Most elements just have to trigger the keyup
or changed
events, but I'm not sure how the flip toggles gets its value from the select box. Any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
更改开关的值后,您必须刷新它才能切换动画:
After you change the value of the switch you have to refresh it for the animation to toggle:
看起来好像坏了。
转到页面: http://jquerymobile.com/demos/ 1.0a2/#docs/forms/forms-switch.html 并使用 firebug 控制台运行以下命令:
它更改开关“on”部分的宽度,但不移动滑块。
所以答案是:等待 JQM 的发布:)
这里发布的 Bug: https: //github.com/jquery/jquery-mobile/issues/issue/676
It looks like it's broken.
Go to the page: http://jquerymobile.com/demos/1.0a2/#docs/forms/forms-switch.html and use firebug console to run the following:
it changes the width of "on" part of the switch, but doesn't move the slider.
So the answer is: wait for the release of JQM :)
Bug issued here: https://github.com/jquery/jquery-mobile/issues/issue/676
实现此目的的一个简单方法是设置值、触发创建和刷新。
然后,您需要触发 Slidestop 事件来执行绑定到滑块的任何操作。例如:
我已经在 jQuery 移动版本上对此进行了测试。 1.3.0
An easy way to achieve this is to set the value, trigger the create and refresh.
Afterwards you need to trigger the slidestop event to perform any action you bound to the slider. eg:
I've tested this on jQuery mobile ver. 1.3.0
我认为你可以像普通 HTML 一样设置 select 中的值,然后翻转切换开关就会自动选择。 IE
I think you can just set the value in select like normal HTML and flip toggle switch will pick up automatically. i.e.
使用
$('#slider2').val('on')
将更改该值,正如预期的那样。但是,它不会将 CSS 类(例如ui-btn-active
)添加到option
中,也不会从option
中删除该类>。如果您想动态更改选项
,那么您将必须手动处理这些部分(而不是 jQuery Mobile)。Using
$('#slider2').val('on')
will change the value, as it is supposed to. However, it does not add the CSS classes such asui-btn-active
to theoption
, nor does it remove that class from the theoption
. If you want to dynamically change theoption
, then you will have to take care of those parts manually (not jQuery Mobile).这对我有用:
This works for me: