bootstrap switch setState给出js错误

rjc*_*ode 5 javascript jquery twitter-bootstrap bootstrap-switch

我试图用Ajax中的条件返回值来改变bootstrap开关的状态,

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);
}
Run Code Online (Sandbox Code Playgroud)

但是它会抛出如下错误.未捕获的TypeError:无法读取未定义的属性'apply'

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)
Run Code Online (Sandbox Code Playgroud)

这个错误的错误是什么?

itz*_*hy7 6

试试这个 ;)

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

$('#limit').bootstrapSwitch('state', true);
$('#limit').bootstrapSwitch('state', false);
Run Code Online (Sandbox Code Playgroud)

@bplittle的/sf/answers/2476258991/