2019独角兽企业重金招聘Python工程师标准>>>

<input type="checkbox" name="my-switch" checked>

js写以下代码,不然switch控件出不来

$("[name='my-switch']").bootstrapSwitch();

$('[name="my-switch"]').bootstrapSwitch({

onText:"启动",

offText:"停止",

onColor:"success",

offColor:"info",

size:"small",

onSwitchChange:function(event,state){

if(state==true){

$(this).val("1");

}else{

$(this).val("2");

}

}

})

上述方法,没有亲测,大家可以试一试!

<div class="make-switch" data-on-label="开" data-off-label="关" id="toggle-state-switch" data-on="success" data-off="warning"><input id ="toggle" type="checkbox"  checked="checked" class="toggle"  />
</div>function changeState(stateValue){if(stateValue==1){$('#toggle-state-switch').bootstrapSwitch('setState', true);}else{$('#toggle-state-switch').bootstrapSwitch('setState', false);}
}

使用上述的方法

$('#toggle-state-switch').bootstrapSwitch('setState', false); 是有问题的。

应该使用

$('#toggle-state-switch').bootstrapSwitch('state', true/false);

还有一个坑,就是在使用外面的div的id设置bootstrapSwitch的state,会多了节点,如下:

这并不是我们想要的结果,所以,设置外置div的值是不对的。应该取checkbox的id设置,也就是,如下:

$('#toggle').bootstrapSwitch('state', false);

对bootstrap switch进行赋值的时候,提示错误 
Uncaught TypeError: Cannot read property 'apply' of undefined

if (isUp==undefined || isUp == ''){$('#isUp').bootstrapSwitch('setState',true);} else{$('#isUp').bootstrapSwitch('setState',isUp);}

详细错误信息如下图所示: 
 
我参考这个设置 使用jQuery获取Bootstrap Switch的值 
看来有问题,于是查看源码,根本没有setState方法,应该使用下面的方法:

if(stateValue==0){$('#toggle').bootstrapSwitch('state', true);console.log("是否启用的状态1:",stateValue);}else{console.log("是否启用的状态2:",stateValue);$('#toggle').bootstrapSwitch('state', false);}

转载于:https://my.oschina.net/maojindaoGG/blog/1612711

bug之bootstrap switch Uncaught TypeError: Cannot read property 'apply' of undefined相关推荐

  1. 【StackFlow】Uncaught TypeError: Cannot read property 'pageCount' of undefined

    Exception 使用Ext JS 4 分页查询时,当查询结果为0时报错: Uncaught TypeError: Cannot read property 'pageCount' of undef ...

  2. chrome浏览器不能录音:Uncaught TypeError: Cannot read property ‘getUserMedia‘ of undefined解决方法

    Uncaught TypeError: Cannot read property 'getUserMedia' of undefined解决方法 javascript 打不开浏览器录音功能的问题解决方 ...

  3. jquery.dataTables.min.js: Uncaught TypeError: Cannot read property 'style' of undefined

    Jquery DataTable使用报这个错: jquery.dataTables.min.js: Uncaught TypeError: Cannot read property 'style' o ...

  4. Uncaught TypeError: Cannot read property ‘events‘ of undefined

    使用谷歌调试页面时,出现如下错误提示: Uncaught TypeError: Cannot read property 'events' of undefined 场景是这样的,我页面中有几个按钮, ...

  5. datatables插件AJAX请求数据报错Uncaught TypeError: Cannot read property ‘length‘ of undefined

    之前常用的表格插件是bootstraptable·,现在换了地方工作,这边用的是datatables.上午再看官网API,感觉写的不是很清晰很到位. 看到一篇博客写的很详细,收藏了.最全的jquery ...

  6. jquery.dataTables.min.js:62 Uncaught TypeError: Cannot read property ‘style‘ of undefined原因

    前些天发现了一个巨牛的人工智能学习网站,通俗易懂,风趣幽默,忍不住分享一下给大家.点击跳转到教程. 报错: jquery.dataTables.min.js:62 Uncaught TypeError ...

  7. 小程序组件报错Uncaught TypeError: Cannot read property 'name' of undefined

    小程序组件报错Uncaught TypeError: Cannot read property 'name' of undefined Component({/*** 组件的属性列表*/propert ...

  8. laydate报Uncaught TypeError: Cannot read property 'appendChild' of undefined

    laydate Uncaught TypeError: Cannot read property 'appendChild' of undefined 我遇到这个错误之后是从两个方向解决的问题 出现了 ...

  9. vue-cli3的项目 CDN链接报错解决 Uncaught TypeError: Cannot read property 'prototype' of undefined at Object.

    Uncaught ReferenceError: iview is not defined 出现这个问题的原因是路径的问题 确保你的路径是正确的,或者是既全局引入了iview,又按需引入,会造成这样的 ...

最新文章

  1. jquery 获取一组元素的选中项 - 函数、jquery获取复选框值、jquery获取单选按钮值...
  2. 【二分查找】及相关问题
  3. 山东大学为中外学生“学伴”项目不当选项致歉
  4. python crawler(1)
  5. linux下的PHP和windows下的php的区别
  6. 团队在Github上协同开发项目流程
  7. 黑苹果hp有声音hdmi无声音_黑科技!不戴耳机也能独享声音!以色列公司推出无耳机传输音乐...
  8. Sharepoint client model 中出现Cannot invoke HTTP DAV request. There is a pending query 的解决办法...
  9. 1.1-1.5-vim编辑器
  10. Vue 基础的开发环境
  11. mysql-5.7.24-linux_Linux下安装mysql-5.7.24
  12. Latex学习--参考文献排版(ieee access 模板)
  13. 在线扒站工具, 扒站网站工具(简单、快捷、免费)
  14. fanuc机器人试题_工业机器人知识要点解析(FANUC机器人)
  15. 爬虫实战——QQ空间自动点赞!这个脚本值三千五你信吗?
  16. Oracle基本认识
  17. 微信语音保存到本地服务器,文件格式由amr转mp3
  18. 妖人柴:都移动互联网时代了,为什么还要建网站?
  19. Kinect结合Unity3D引擎开发体感游戏(二)
  20. thinkpad T480安装WIN7

热门文章

  1. Elasticsearch创建索引和映射结构详解
  2. OpenCV Python教程(3)(4)(5): 直方图的计算与显示 形态学处理 初级滤波内
  3. 分类器评价与在R中的实现:收益图与提升图
  4. 代码之谜(一)- 有限与无限
  5. 我犯了一个错误,您能指出吗?(结论)
  6. 我的C++学习历程(old)
  7. Stanford UFLDL教程 稀疏编码
  8. 保障IDC安全:分布式HIDS集群架构设计
  9. [实战]HM-Router configuration for TP ROOM
  10. RDS最佳实践(三)—如何制定相关的流程来规范RDS的使用