如何使用 jquery 获取 twitter bootstrap 切换开关值

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/20707921/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-27 01:16:01  来源:igfitidea点击:

How to get twitter bootstrap toggle switch values using jquery

jquerytwitter-bootstrap

提问by lalith458

I am using http://bootstrapswitch.site/for toggle switch buttons. How can I get the toggle switch like 'on' or 'off' using jQuery?

我使用http://bootstrapswitch.site/作为切换开关按钮。如何使用 jQuery 获得“开”或“关”之类的切换开关?

My Code is :

我的代码是:

<div class="make-switch  switch-small"><input type="radio" class="nsfw"></div>

Please tell me how to solve this issue.

请告诉我如何解决这个问题。

回答by janhartmann

$('#switcher').bootstrapSwitch('state'); // true || false
$('#switcher').bootstrapSwitch('toggleState');

Refer this linkfor more functions

更多功能请参考此链接

回答by bplittle

As far as I can tell the method has been updated (but not well documented).

据我所知,该方法已更新(但没有很好的记录)。

$('#switcher').bootstrapSwitch('state', true)
$('#switcher').bootstrapSwitch('state', false)

回答by Hajime

About changing state in my case,

关于在我的情况下改变状态,

('#switcher').bootstrapSwitch('state', false); 

It's correct code.

这是正确的代码。