onInit回调bootstrap开关来检查元素的初始状态(onInit callback of bootstrap switch to check initial state of element)

编程入门 行业动态 更新时间:2024-10-28 06:27:47
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')); } });

更多推荐

本文发布于:2023-08-05 06:05:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1428754.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:回调   元素   状态   bootstrap   onInit

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!