简体   繁体   English

引导程序开关的onInit回调,以检查元素的初始状态

[英]onInit callback of bootstrap switch to check initial state of element

I need to check the current state of a particular bootstrap switch element on page-load and wanted to solve that with the onInit-Callback. 我需要在页面加载时检查特定引导程序开关元素的当前状态,并想通过onInit-Callback解决该问题。 Unfortunately it gives mit "undefined" when I ask for the current state. 不幸的是,当我要求当前状态时,它给mit“未定义”。 Here is my code so far... 到目前为止,这是我的代码...

$(".make-switch").bootstrapSwitch({
onText:'ja',
offText:'nein',
onColor:"success",
offColor:"warning",
indeterminate: true,
size:"big",
onInit:function(event,state)
    {
    var current_element=$(this).attr("id");
        if(current_element=="has-emotion")
        {

        alert(state); //gives me "undefined" for this and every other element


        }});

My Bootstrap-Switch Version is v3.3.2 and Jquery Version 2.1.4 我的Bootstrap-Switch版本是v3.3.2和Jquery版本2.1.4

What am I doing wrong here? 我在这里做错了什么? Or is there an other way to check the state of the given element when loading the page? 还是在加载页面时有其他方法检查给定元素的状态?

Thank you very much! 非常感谢你! Regards from Austria 来自奥地利的问候

You can do this like : 您可以这样做:

$('.make-switch').bootstrapSwitch({        
    onInit:function (event, state) {                        
        alert($(this).is(':checked'));
     }
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM