【问题标题】:bootstrap switch setState gives js error引导开关 setState 给出 js 错误
【发布时间】:2016-12-19 10:35:10
【问题描述】:

我正在尝试使用来自 Ajax 的条件返回值来更改引导开关的状态,

HTML,

<input type="checkbox" id="limit" class="make-switch"  data-on-text="Yes" data-off-text="No" data-on="success" data-on-color="success" data-off-color="danger" data-size="small">

<input type="text" name="limit_amount" id="limit_amount" autocomplete="off"  class="form-control"  readonly>


if(objData.limit === 'Yes')
{
  $('#limit').bootstrapSwitch('setState', true);
  $("#limit_amount").prop("readonly", false);
}
else {
    $('#limit').bootstrapSwitch('setState', false);
    $("#limit_amount").prop("readonly", true);
}

但它会抛出如下错误.. Uncaught TypeError: Cannot read property 'apply' of undefined

Uncaught TypeError: Cannot read property 'apply' of undefined
at HTMLInputElement.<anonymous> (bootstrap-switch.min.js:22)
at Function.each (jquery.min.js:2)
at n.fn.init.each (jquery.min.js:2)
at n.fn.init.e.fn.bootstrapSwitch (bootstrap-switch.min.js:22)
at Object.success (limitingcat.js:311)
at i (jquery.min.js:2)
at Object.fireWith [as resolveWith] (jquery.min.js:2)
at y (jquery.min.js:4)
at XMLHttpRequest.c (jquery.min.js:4)

这个bug有什么问题吗?

【问题讨论】:

  • 可以分享html吗?
  • @itzmukeshy7,添加了 HTML

标签: javascript jquery twitter-bootstrap bootstrap-switch


【解决方案1】:

试试这个;)

据我所知,该方法已更新(但没有详细记录)。

$('#limit').bootstrapSwitch('state', true);
$('#limit').bootstrapSwitch('state', false);

https://stackoverflow.com/a/35375128/2922854@bplittle

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-01-21
    • 2020-06-21
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多