本文介绍了如何从代码更改 jquery 移动翻转开关状态的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的 Android/iPad 应用程序上有一些 jQuery Mobile 翻转切换开关,我需要使用 JavaScript 动态更改它们的状态(开/关).我在这里寻找解决方案,(更改翻转切换值动态使用 jQuery Mobile) 并且我尝试了几种方法 (.val('on'), .slider('enable')...) 但它似乎控件根本不起作用.

I have some jQuery Mobile flip toggle switches on my Android/iPad application, and I need tochange their states (on/off) dynamically, using JavaScript.I was looking for a solution here, (Change value of flip toggle dynamically with jQuery Mobile) and I tried several ways (.val('on'), .slider('enable')...) but it seems the control is not working at all.

这个问题有解决方案吗?如何从代码中更改翻转开关状态?

Is there a solution for this issue? How can I do to change the flip switch state from code?

推荐答案

我已经检查了您发布的页面,并确认了解决方案:

I've examined the page you posted and I confirmed that the solution:

$('selector').val('value').slider('refresh');

确实有效.确保选择器"引用您的选择元素,并且值"是您在要启用的选项元素上定义的值.

does indeed work. Make sure that 'selector' is referencing your select element, and that 'value' is a value you defined on the option element you wish to enable.

我通过访问 http://jquerymobile.com/demos/1.0 确认了这一点.1/docs/forms/switch/index.html,然后用 firebug 的控制台输入该行:

I confirmed this by visiting http://jquerymobile.com/demos/1.0.1/docs/forms/switch/index.html, then with firebug's console entering the line:

$("#flip-b").val('no').slider('refresh');

它将页面上显示的第二个滑块从是到否.

It switched the second slider displayed on the page from yes to no.

这篇关于如何从代码更改 jquery 移动翻转开关状态的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-15 04:50