【问题标题】:Change the status of toggle using jquery [duplicate]使用jquery更改切换状态[重复]
【发布时间】:2019-05-22 08:28:51
【问题描述】:

我正在尝试使用 jquery 更改切换开关的状态,但没有成功。 这是jquery的代码

$('#bandwidthcap').checked='false';

我试过用这种方式

$('#bandwidthcap').attr('checked','false')

这是html的代码

<input type="checkbox"  name="bandwidthcap" id="bandwidthcap" class="switchery" data-color="primary"/>

【问题讨论】:

    标签: javascript jquery checkbox bootstrap-4


    【解决方案1】:

    您可以使用 .prop() 函数:

    $('#bandwidthcap').prop("checked", true)
    <input type="checkbox" name="bandwidthcap" id="bandwidthcap" class="switchery" data-color="primary" />
    <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-11-17
      • 1970-01-01
      • 1970-01-01
      • 2011-11-16
      • 2023-03-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多