onInit回调bootstrap开关来检查元素的初始状态(onInit callback of bootstrap switch to check initial state of element)
我需要在页面加载时检查特定引导程序开关元素的当前状态,并想用onInit-Callback来解决这个问题。 不幸的是,当我询问当前状态时,它给出了“未定义”。 这是我的代码到目前为止...
$(".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 }});我的Bootstrap-Switch版本是v3.3.2和Jquery版本2.1.4
我在这里做错了什么? 还是有其他的方式来检查加载页面时给定元素的状态?
非常感谢你! 来自奥地利的问候
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. Unfortunately it gives mit "undefined" when I ask for the current state. 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
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
最满意答案
你可以这样做:
$('.make-switch').bootstrapSwitch({ onInit:function (event, state) { alert($(this).is(':checked')); } });You can do this like :
$('.make-switch').bootstrapSwitch({ onInit:function (event, state) { alert($(this).is(':checked')); } });更多推荐
发布评论