选中取消选中切换器

Check uncheck switcher

您好,我正在使用 abpetkov/switchery 渲染那些漂亮的开关。我面临一个问题,我想使用 jquery 启用或禁用开关,启用和禁用我的意思是选中和取消选中。我不知道该怎么做。有人能告诉我怎么做吗我是这样渲染的

<table>
    <tr>
      <td>
        <input type='checkbox' name='record-call' data-render='switchery' data-theme='default' id="abcd"  /></td>
      </td>
    </tr>   
</table>

我面临的问题是每当我尝试像这样选中或取消选中切换器时 $( "#hour-1" ).prop( "checked", true ); 它 checks/unchecks 复选框但不影响切换器

捕获onchange事件,然后触发click事件。我有点像这样 e.next.click() 你一定想知道我为什么写下一篇。好吧,如果你检查你的输入框,你会看到输入框下面有一个跨度。那是你的切换器。只需触发点击事件即可。

<table>
    <tr>
      <td>
        <input type='checkbox' name='record-call' data-render='switchery' data-theme='default' id="abcd"  onchange="fun(this)"/></td>
      </td>
    </tr>   
</table>


function fun(e){
   e.next.click()
}

希望对您有所帮助。有什么不明白的可以尽管问。